Display a code block with optional syntax highlighting.

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

Function signature

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

Parameters

body (str)

The string to display as code.

language (str or None)

The language that the code is written in, for syntax highlighting. If None, the code will be unstyled. Defaults to "python".

For a list of available language values, see:

https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_LANGUAGES_PRISM.MD

Example

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

Was this page helpful?

editSuggest edits
forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.