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 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:



import streamlit as st

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.