Display a code block with optional syntax highlighting.

Function signature[source]

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


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:


line_numbers (bool)

An optional boolean indicating whether to show line numbers to the left of the code block. Defaults to False.


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.