# How to reduce the top blank area height of streamlit app?

**URL:** <https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057>\
**Category:** Using Streamlit\
**Created:** [October 13, 2021, 5:48am UTC](https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057 "2021-10-13T05:48:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BeyondMyself](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/beyondmyself/32/7525_2.png) [@BeyondMyself](https://discuss.streamlit.io/u/BeyondMyself)\
**Post date:** [October 13, 2021, 5:48am UTC](https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057/1 "2021-10-13T05:48:06Z")

</div>

When we start a streamlit app, after open explorer, we will see a huge blank area at the top.  
How can we control the blank height with some argument and where we can do this?  
Thank you.

---

<div class="post-metadata">

**Author:** ![asehmi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/asehmi/32/1771_2.png) [@asehmi](https://discuss.streamlit.io/u/asehmi)\
**Post date:** [October 13, 2021, 2:24pm UTC](https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057/2 "2021-10-13T14:24:22Z")

</div>

I adapted this from @Marc’s [Awesome Streamlit Resources](https://discuss.streamlit.io/t/awesome-streamlit-resources-and-gallery/323) app.

```python

BACKGROUND_COLOR = 'white'
COLOR = 'black'

def set_page_container_style(
        max_width: int = 1100, max_width_100_percent: bool = False,
        padding_top: int = 1, padding_right: int = 10, padding_left: int = 1, padding_bottom: int = 10,
        color: str = COLOR, background_color: str = BACKGROUND_COLOR,
    ):
        if max_width_100_percent:
            max_width_str = f'max-width: 100%;'
        else:
            max_width_str = f'max-width: {max_width}px;'
        st.markdown(
            f'''
            <style>
                .reportview-container .sidebar-content {{
                    padding-top: {padding_top}rem;
                }}
                .reportview-container .main .block-container {{
                    {max_width_str}
                    padding-top: {padding_top}rem;
                    padding-right: {padding_right}rem;
                    padding-left: {padding_left}rem;
                    padding-bottom: {padding_bottom}rem;
                }}
                .reportview-container .main {{
                    color: {color};
                    background-color: {background_color};
                }}
            </style>
            ''',
            unsafe_allow_html=True,
        )

```

---

<div class="post-metadata">

**Author:** ![BeyondMyself](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/beyondmyself/32/7525_2.png) [@BeyondMyself](https://discuss.streamlit.io/u/BeyondMyself)\
**Post date:** [October 13, 2021, 2:30pm UTC](https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057/3 "2021-10-13T14:30:29Z")

</div>

> [@asehmi](#):
>
> ```auto
> BACKGROUND_COLOR = 'white'
> COLOR = 'black'
> 
> def set_page_container_style(
> max_width: int = 1100, max_width_100_percent: bool = False,
> padding_top: int = 1, padding_right: int = 10, padding_left: int = 1, padding_bottom: int = 10,
> color: str = COLOR, background_color: str = BACKGROUND_COLOR,
> ):
> if max_width_100_percent:
> max_width_str = f'max-width: 100%;'
> else:
> max_width_str = f'max-width: {max_width}px;'
> st.markdown(
> f'''
> <style>
> .reportview-container .sidebar-content {{
> padding-top: {padding_top}rem;
> }}
> .reportview-container .main .block-container {{
> {max_width_str}
> padding-top: {padding_top}rem;
> padding-right: {padding_right}rem;
> padding-left: {padding_left}rem;
> padding-bottom: {padding_bottom}rem;
> }}
> .reportview-container .main {{
> color: {color};
> background-color: {background_color};
> }}
> </style>
> ''',
> unsafe_allow_html=True,
> )
> 
> ```

it works, change the padding-top argument, blank area height is changed.  
Thank you very much.

---

<div class="post-metadata">

**Author:** ![Roshan](https://avatars.discourse-cdn.com/v4/letter/r/58f4c7/32.png) [@Roshan](https://discuss.streamlit.io/u/Roshan)\
**Post date:** [October 20, 2021, 12:49pm UTC](https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057/4 "2021-10-20T12:49:31Z")

</div>

Hello there, I hope you are doing great.  
So, I have been trying to create a mini project in Streamlit and I have ran into the padding issues. I used Marc’s code (the above styling you suggested) but it isn’t working for the sidebar. It actually doesn’t even work for the original content. There’s still some padding for some reason. I will share the screenshot of the page and the code I used.

 ![image](https://global.discourse-cdn.com/streamlit/original/2X/9/91b230bec058abc8ad2ec561c0dbd2f361ea92f9.png)

```auto
padding_top = 0
padding_bottom = 10
padding_left = 1
padding_right = 10
# max_width_str = f'max-width: 100%;'
st.markdown(f'''
            <style>
                .reportview-container .sidebar-content {{
                    padding-top: {padding_top}rem;
                }}
                .reportview-container .main .block-container {{
                    padding-top: {padding_top}rem;
                    padding-right: {padding_right}rem;
                    padding-left: {padding_left}rem;
                    padding-bottom: {padding_bottom}rem;
                }}
            </style>
            ''', unsafe_allow_html=True,
)

```

I hope I addressed my problem clearly. Thank you for your help!

---

<div class="post-metadata">

**Author:** ![asehmi](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/asehmi/32/1771_2.png) [@asehmi](https://discuss.streamlit.io/u/asehmi)\
**Post date:** [October 20, 2021, 4:42pm UTC](https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057/5 "2021-10-20T16:42:35Z")

</div>

I think the layout classes have changed in the latest Streamlit versions. As you know this is _not_ a recommended method of adjusting layout styles; essentially it’s a hack - `unsafe_allow_html=True` is a clue! 🙂

I see that the sidebar is no longer enclosed in a div with class `sidebar-content`. If you open the browser’s dev tools (F12) you can see that the class names are probably custom generated, or at least you can’t rely on finding a stable class name container path like `.reportview-container .main .block-container`. Therefore, find the specific classes for the sidebar in your app and set their attributes in your code. Here’s what I had to do to make the sidebar content v-align with the main content.

```auto
        st.markdown(
            f'''
            <style>
                .reportview-container .css-1lcbmhc .css-1outpf7 {{
                    padding-top: 35px;
                }}
                :
                :
               etc.
                :
                :
            </style>
            ''',

```

Notice my sidebar container path is `.reportview-container .css-1lcbmhc .css-1outpf7`. and by experimenting I arrived at `padding-top: 35px`.

HTH  
Arvindra

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [October 20, 2022, 4:43pm UTC](https://discuss.streamlit.io/t/how-to-reduce-the-top-blank-area-height-of-streamlit-app/18057/6 "2022-10-20T16:43:22Z")

</div>

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