Display a code block with optional syntax highlighting.

(This is a convenience wrapper around st.markdown())

Function signature

st.code(body, language="python")


body (str)

The string to display as code.

language (str)

The language that the code is written in, for syntax highlighting. If omitted, the code will be unstyled.


code = '''def hello():
     print("Hello, Streamlit!")'''
st.code(code, language='python')

Was this page helpful?

editSuggest edits

Still have questions?

Our forums are full of helpful information and Streamlit experts.