How do I change the font size of the streamlit radio button’s label?
st.radio(label = 'Highest Rated Restaurants', options = top_ranked_restaurants)
I have this code and I want to change the font size of ‘Highest Rated Restaurants’.
How do I change the font size of the streamlit radio button’s label?
st.radio(label = 'Highest Rated Restaurants', options = top_ranked_restaurants)
I have this code and I want to change the font size of ‘Highest Rated Restaurants’.
Hey @Ardash_Wase,
There’s no clean and native way to do that in Streamlit but if you feel like hacking some CSS, then here’s a solution (toggle the ‘Show code’ expander):
Hi @arnaud,
The way you suggest will result in all the radio widgets on the page having the font size as 32px.
What if you wanted to:
With the following way, I can target any widget, (even add multiple style attributes as function parameters)
import streamlit as st
import streamlit.components.v1 as components
st.set_page_config(layout = "wide", initial_sidebar_state = "expanded")
def ChangeWidgetFontSize(wgt_txt, wch_font_size = '12px'):
htmlstr = """<script>var elements = window.parent.document.querySelectorAll('*'), i;
for (i = 0; i < elements.length; ++i) { if (elements[i].innerText == |wgt_txt|)
{ elements[i].style.fontSize='""" + wch_font_size + """';} } </script> """
htmlstr = htmlstr.replace('|wgt_txt|', "'" + wgt_txt + "'")
components.html(f"{htmlstr}", height=0, width=0)
c1, c2 = st.columns(2)
c1.radio(label='Highest Rated Restaurants', options=("In-And-Out", "Tercera"))
c2.radio(label='Highest Rated Hotels', options=("Taj", "4 Seasons"))
ChangeWidgetFontSize('Highest Rated Restaurants')
ChangeWidgetFontSize('Highest Rated Hotels', '26px')
The only drawback with this method is that it adds a blank line for every invocation of the components.html statement.
Cheers
@arnaud what about changing the font size/family of radio options?
@Shawn_Pereira’s method seems to be the most flexible method for changing labels. See this discussion also for similar usage of components API or even latex.
Hi @Shawn_Pereira and how I could change size for Taj and 4 seasons together along the title?
Thanks!
Hi @arnaud and how I could change size for Taj and 4 seasons together along the title?
Thanks!
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.