st.iframe
Embed content in an iframe.
st.iframe embeds external URLs, HTML content, or local files in an iframe. It auto-detects the input type and handles it appropriately.
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) | |
| 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. |
Examples
Embed an external website:
import streamlit as st
st.iframe("https://docs.streamlit.io", height=600)
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.