How to use html in st.selectbox()

hello there, I am trying to change the color of above text of selectbox with the help of html.
but it shows error “TypeError: selectbox() got an unexpected keyword argument ‘unsafe_allow_html’”

Code -
vehicle = [‘Two-seater’,‘Minicompact’,‘Compact’,‘Subcompact’,‘Mid-size’,‘Full-size’,‘SUV: Small’]
Vehicle_class = st.selectbox(“

Select the vehicle class

”,unsafe_allow_html=True,options = vehicle)

my background black color is getting mixed with black text, so want to change text color.

It’s not possible to throw in unsafe_allow_html=True arbitrarily to any widget. You will either need to set the text color in your theme or inject CSS.

If you need to control the color independently of other font in the app:

import streamlit as st

vehicle = ['Two-seater','Minicompact','Compact','Subcompact','Mid-size','Full-size','SUV: Small']
Vehicle_class = st.selectbox('Select the vehicle class', options = vehicle)

css = '''
<style>
    .stSelectbox [data-testid='stMarkdownContainer'] {
        color: yellow;
    }
</style>
'''

st.markdown(css, unsafe_allow_html=True)

image

thank you for your help,
but this works only wherever select box exist, other input_number() cells text are still in black color

Correct. You can set custom color for specific things, or you can set a font color globally with the theme.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.