Declare the CSS code first and then the buttons you will use.
import streamlit as st
st.header("My custom Button 💫")
st.markdown("""
<style>
.st-emotion-cache-1vbkxwb p{
font-family: 'Comic Sans MS';
}
</style>
""", unsafe_allow_html=True)
st.button("regular button 1")
st.button("Comic Sans Button")
st.button("regular button 2")
st.button("regular button 3")
st.button("regular button 4")
st.button("regular button 5")
This is the HTML element of the Streamlit button: <div data-testid="stMarkdownContainer" class="st-emotion-cache-1vbkxwb e1nzilvr5"><p>Comic Sans Button</p></div>
So if we want to modify the font type, we access it through the class name and the paragraph within the div using CSS:
.st-emotion-cache-1vbkxwb p{
font-family: 'Comic Sans MS';
}
That class is not guaranteed to be stable across streamlit versions – if you’d like, there is a module in streamlit extras that makes it easier to target a specific widget 🎨 Styleable Container - streamlit-extras