Insert HTML into your app.

Adding custom HTML to your app impacts safety, styling, and maintainability. We sanitize HTML with DOMPurify, but inserting HTML remains a developer risk. Passing untrusted code to st.html or dynamically loading external code can increase the risk of vulnerabilities in your app.

st.html content is not iframed. Executing JavaScript is not supported at this time.

Function signature[source]

st.html(body)

Parameters

body (str)

The HTML code to insert, or path to an HTML code file which is loaded and inserted.

If the provided string is the path of a local file, Streamlit will load the file and render its contents as HTML. Otherwise, Streamlit will render the string directly as HTML.

Example

import streamlit as st

code = """
<style>
    p {
        color: red;
    }
</style>
"""
st.html(code)
st.markdown("Lorem ipsum")
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.