Can the label in st.expander() be multi-line?

I’m trying to use

with st.expander(label):

I wonder if the label can be made multi-line? I tried to use " + ‘\n’ " in the creation of label but it doesn’t work. Moreover, the spaces in label gets ignored when shown. For instance, label might be:

label = “this is my label” + " " + “this dataframe has n rows”

And all those large spaces gets shown as a single space it seems. So I wonder if there are ways to format the label in st.expander() that allows for either multi-line string, or additional spacing within the string.


It works for me when I double-up on the newline character:

import streamlit as st

with st.expander('This\n\nis\n\nmultiline'):


Yes, just add \n twice

import streamlit as st

with st.expander("this is my label\n\n this dataframe has n rows"):
    st.write("Row 1")
    st.write("Row 2")

the widget:

on expanding:

1 Like