Custom the form background-color

Summary

Hey everyone ! :wave:
I’m turning to you for a little custom problem with one of my apps. As the title suggests, I’m trying to change the background color of a form. I’ve tried st.markdown but can’t find the right combination, which is where I need your help!
Thanks in advance ! :blush:

Steps to reproduce

Code snippet:
first try :

st.markdown("""
    <style>
    .stForm {
        background-color: #000000;
    }
    </style>
""", unsafe_allow_html=True)

Second try, using the class from web inspector

st.markdown("""
    <style>
    .st-emotion-cache-r421ms e10yg2by1 {
        background-color: #000000;
    }
    </style>
""", unsafe_allow_html=True)

And some alternative like :

  • st-emotion-cache-r421ms .e10yg2by1
  • st-emotion-cache-r421ms
  • div form
  • using !important

Expected behavior:

So I just want to change the background color of my form and not using the transparent default

Debug info

  • Streamlit version: streamlit==1.27.2
  • Python version: 3.10.9
  • PipEnv
  • OS version: Windows 10
  • Browser version: firefox 118.0.1
import streamlit as st

with st.form("My form"):
    first = st.text_input("First name")
    last = st.text_input("Last name")
    if st.form_submit_button("Submit"):
        st.write(first+" "+last)

css="""
<style>
    [data-testid="stForm"] {
        background: LightBlue;
    }
</style>
"""
st.write(css, unsafe_allow_html=True)

1 Like

I’m not very familiar with syntax […], I didn’t know! So thank you so much Debbie (@mathcatsand)! :raised_hands: :heart_hands:

1 Like

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