# Iframe

- **Section:** Components
- **URL:** https://refast.fastapicloud.dev/docs/components/iframe
- **Markdown:** https://refast.fastapicloud.dev/docs/components/iframe.md
- **Source:** https://github.com/idling-mind/refast-docs/blob/main/docs/pages/components/utility/iframe.py
- **Live examples:** the widgets on this page need a browser; open the URL above to try them.
- **Applies to:** refast 0.12.2

Embeds external websites or inline HTML content securely and responsively
within your Refast layouts.

```python
from refast.components import Iframe

Iframe(src="https://example.com", title="External Site")
```

```python
Iframe(
    src="https://www.wikipedia.org",
    title="Iframe Embed",
    width="100%",
    height="400px",
    class_name="border rounded",
)
```

## Props

| Prop | Type | Default | Description |
|------|------|---------|-------------|
| `src` | `str \| None` | `None` | The URL of the page to embed. |
| `srcdoc` | `str \| None` | `None` | Inline HTML to embed (takes precedence over `src`). |
| `title` | `str \| None` | `None` | Title of the iframe (important for accessibility). |
| `name` | `str \| None` | `None` | Name of the iframe. |
| `allow` | `str \| None` | `None` | Feature policy permissions (e.g. `geolocation`). |
| `sandbox` | `str \| None` | `None` | Sandbox restrictions (e.g. `allow-scripts`). |
| `referrer_policy` | `str \| None` | `None` | Referrer policy for loading the iframe. |
| `loading` | `Literal["lazy", "eager"]` | `"lazy"` | Browser loading strategy. |
| `width` | `int \| str \| None` | `None` | Width of the iframe (pixels or CSS string). |
| `height` | `int \| str \| None` | `None` | Height of the iframe (pixels or CSS string). |

## Basic External Embed

```python
Iframe(
    src="https://example.com",
    title="Example Domain",
    width="100%",
    height=400,
)
```

## Inline HTML content (srcdoc)

You can render custom, styling-isolated HTML structures directly without making a
separate HTTP request using the `srcdoc` property:

```python
Iframe(
    srcdoc="<div style='color: blue;'>Hello World</div>",
    title="Inline Frame",
    width="100%",
    height=200,
)
```

## Security Sandboxing

When embedding untrusted external contents, it's highly recommended to apply sandbox constraints:

```python
Iframe(
    src="https://example.com",
    title="Sandboxed Content",
    sandbox="allow-scripts allow-same-origin",
)
```

---

Part of the Refast documentation: [all pages](https://refast.fastapicloud.dev/llms.txt), [everything on one page](https://refast.fastapicloud.dev/llms-full.txt), [search](https://refast.fastapicloud.dev/api/search?q=save_prop).
