Search code examples
python-3.xstreamlit

How to remove extra spacing before the title in streamlit?


I've built a basic streamlit app. I am would like to know if there is a way to remove the extra space above the title. In the attached image you can see a noticeable gap between address bar and title

enter image description here


Solution

  • You can do it by injecting some css inside the view:

    import streamlit as st
    
    st.set_page_config(layout="wide")
    
    padding_top = 0
    
    st.markdown(f"""
        <style>
            .reportview-container .main .block-container{{
                padding-top: {padding_top}rem;
            }}
        </style>""",
        unsafe_allow_html=True,
    )
    
    st.title("My Next Best Actions")
    
    st.sidebar.text_input("foo")
    

    Lower padding on top of the title]