Embed renders an iframe for external content. Pass a url for hosted content (YouTube, Google Maps, PDFs) or html for custom HTML/JS (Three.js scenes, Canvas visualizations, shader previews).
Basic Usage
Any URL that works in an iframe works here. The first positional argument isurl, so Embed("https://...") works as shorthand.
- Google Maps
- YouTube
- Spotify
HTML Mode
For custom content like interactive visualizations, pass raw HTML via thehtml parameter. The content runs in an isolated iframe, so it can include <script> tags, Canvas, WebGL, or any client-side code:
From Embed Code
Services like YouTube, Google Maps, and Spotify provide embed codes as raw<iframe> HTML. Embed.from_iframe() parses the tag and extracts src, width, height, allow, and sandbox automatically — just paste the snippet:
Pasting an embed code
height="352") are automatically converted to CSS values ("352px"). Any keyword arguments override the parsed attributes.
Sandbox and Permissions
Embed exposes two standard HTML iframe attributes for controlling what the embedded content can do: sandbox and allow. These are independent of each other — sandbox restricts capabilities, allow grants access to browser APIs.
sandbox
The HTMLsandbox attribute restricts the iframe’s capabilities. By default, no sandbox is applied — the iframe has full capabilities. Set sandbox to a space-separated list of permissions to restrict what the content can do:
Restricting capabilities
allow-scripts, allow-same-origin, allow-forms, allow-popups, allow-modals.
allow
The HTMLallow attribute controls which browser Permissions Policy features are available to the embedded content — things like fullscreen, autoplay, camera, microphone, and geolocation. Most embeds don’t need this; it’s primarily relevant for video embeds (fullscreen button) or content that accesses device APIs:
Feature policies
API Reference
Embed Parameters
URL to embed (iframe
src). Mutually exclusive with html.HTML content to embed (iframe
srcdoc). Mutually exclusive with url.CSS width value with units (e.g.,
"100%", "640px").CSS height value with units.
Iframe sandbox attribute. Space-separated list of permissions like
"allow-scripts allow-same-origin".Iframe allow attribute for feature policies like
"fullscreen; autoplay".Additional Tailwind CSS classes.
Protocol Reference
Embed