I would like to know if it is possible to change the font for the entire application.
I saw in the customization of themes that streamlit uses the sans-serif font as default, I would like to use the font-family: “Cabin”, sans-serif;
I’d like to use it for all the app, text, widgets, etc.
I tried using some CSS like @andfanilo shows in his youtube video (By the way thanks for the amazing content! I’m your fan!). But I believe my CSS skills are not good enough.
I configured the config file, however it only accepts some fonts (“sans serif”, “serif”, or “monospace”.) the font I want to use seems to be not supported.
Here the message that I receive when try to set font = “cabin” (or Cabin)
2022-06-02 19:08:23.003 “cabin” is an invalid value for theme.font. Allowed values include [‘sans serif’, ‘serif’, ‘monospace’]. Setting theme.font to “sans serif”.
Is there any way I can put a global font other than the ones that are available?
Thank you for this Ricardo! It works for almost everything, but doesn’t seem to style AgGrid. I’ve tried using the custom_css parameter to set the AgGrid theme font-family attribute, but haven’t had luck. for example, using your code above, I can render all text outside of the AgGrid component with the Poppins font, but the AgGrid renders with Times New Roman.
The solution proposed by @ricardo.pascoal will work on the current (1.31.1) streamlit distribution with one modification to the css selector being used along with adding the !important modifier to the font-family.
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@100&display=swap');
body * {
font-family: 'Roboto', sans-serif !important;
}
with the code in your main.py the same as he suggests:
with open( "app\style.css" ) as css:
st.markdown( f'<style>{css.read()}</style>' , unsafe_allow_html= True)
Note: using body * will essentially override the font for every element. When that is not the desired effect you may want to inspect your page in a web editor and tweak your CSS selector to more refined targets. This becomes obvious when you look at st.code() code blocks as their monospace font will be replaced by your custom font.
In my case I noticed that all of the streamlit elements that I wanted my font to affect contained a class that starts with st-emotion. Therefor my CSS selector looks like the following:
The above change from using body * allows any inline styles to remain applied as they relate to the font. Such as allowing the formatting of st.code() blocks to remain intact.
Just place it in a .css file and name it anything you want. Just make sure to change the file name in the python file so it finds your css file correctly.