st.iframe
Embed content in an iframe.
st.iframe embeds external URLs, HTML content, or local files in an iframe. It handles the input based on its type and URL pattern.
Warning
HTML strings, local HTML files, and same-origin relative URLs are embedded as-is in an iframe that allows JavaScript execution and same-origin access to the Streamlit app. Never pass untrusted HTML or untrusted src values from users, query parameters, databases, uploaded files, LLM output, or other external sources to st.iframe. Use st.html for sanitized HTML snippets that don't need full iframe behavior.
| Function signature[source] | |
|---|---|
st.iframe(src, *, width="stretch", height="content", tab_index=None, alt=None) | |
| Parameters | |
src (str or Path) | The content to embed. This can be one of the following:
|
width (int, "stretch", or "content") | The width of the iframe. This can be one of the following:
|
height (int, "stretch", or "content") | The height of the iframe. This can be one of the following:
|
tab_index (int or None) | Controls keyboard navigation focus. This can be one of the following:
For more information, see the tabindex documentation on MDN. |
alt (str or None) | A description of the embed for screen readers and other assistive technologies. Streamlit maps this to the iframe's title attribute, which is the frame's accessible name. If this is None (default), the title stays "st.iframe". An empty or whitespace-only string is treated the same as None and is logged so authors notice the dual meaning of alt="" across commands (decorative only on st.image / st.pyplot). An iframe must have a title, so empty alt keeps the "st.iframe" fallback rather than becoming decorative. Describe the embedded content rather than repeating text that is already visible on the page. |
Examples
Embed an external website:
import streamlit as st
st.iframe(
"https://docs.streamlit.io",
height=600,
alt="Streamlit documentation",
)
Embed HTML content directly:
import streamlit as st
st.iframe(
'''
<style>body { font-family: sans-serif; padding: 1rem; }</style>
<p>This is <strong>embedded HTML</strong>.</p>
''',
height=100,
)
Embed a local HTML file:
import streamlit as st
from pathlib import Path
st.iframe(Path("reports/dashboard.html"), height=800)
Still have questions?
Our forums are full of helpful information and Streamlit experts.