How would I go about changing the font properties (font size, weight, etc.) of st.sidebar widget labels? For example, city, state, and age in the screenshot. I want to increase the font size of the labels only, not the font size of the drop down text.
Hey there, thanks for your question and welcome to the Streamlit community!
Customizing the font properties (like size and weight) of st.sidebar widget labels isn’t natively supported via the Streamlit API or theme config. The official theming options in config.toml let you set the overall font family and base size for the sidebar, but not specifically for widget labels only—these settings apply to all sidebar text, including dropdown options and other elements, not just the labels themselves. See the official theming docs for details.
If you want to target just the labels, the only current workaround is to inject custom CSS using st.markdown(..., unsafe_allow_html=True). This method is a bit hacky and may break with future Streamlit updates, but it’s commonly used in the community. For example, you can use a CSS selector to increase the font size of sidebar widget labels:
import streamlit as st
st.markdown("""
<style>
/* This targets all sidebar widget labels */
section[data-testid="stSidebar"] label {
font-size: 20px !important;
font-weight: bold !important;
}
</style>
""", unsafe_allow_html=True)
# Example sidebar widgets
st.sidebar.selectbox("City", ["All", "New York", "San Francisco"])
st.sidebar.selectbox("State", ["All", "CA", "NY"])
st.sidebar.slider("Age", 18, 100, (18, 100))
This will increase the font size and weight of all sidebar widget labels, but not the dropdown options or slider values. Note that CSS selectors may change in future Streamlit versions, so always test after upgrades. For more discussion and examples, see this forum thread and this one.
Sources:
