Remove whitespace between st.markdown

Hi !
I’m using streamlit expander, in which I have a some text displayed with st.write(), then some text displayed with st.markdown(), then finally an image. My problem is that between the 2nd markdown and the elements around it, there is a huge amount of space. It should look like this:

"This app aims at providing a simple user interface to do some stuff "

But instead looks like this :

This app aims at providing a simple user interface to do some stuff


I understand from some other streamlit community posts that this is due to CSS whitespace. Do you know how I could vanish, or reduce the size of, this whitespace?

Here is my code (I’m looping on a json file called “apps”: one app = one expander) :

padding_top = 0
padding_bottom = 0

for k in range(len(apps)):
    with st.expander():
         st.write("**Users:** ", apps[k]['desk'][0])
         st.write("**Category:** ", apps[k]['category'][0])

        # paste a text with a fixed size for all expanders using st.markdown
        description = utils.constrain_text(160, apps[k]['description'])
                         <div class="description" style="white-space: pre-wrap;margin-bottom: 1px; padding: 0;padding-top: {padding_top}rem;
                    padding-bottom: {padding_bottom}rem;">
                                                 <h1 style="font-size: 15px; margin: 0; font-weight: normal;padding: 0;padding-top: {padding_top}rem;
                    padding-bottom: {padding_bottom}rem">{description}</h1>

That is because the newlines in your html.

Hi @ClaraBird

Yes, you can use CSS styling to modify the spacing between the elements (the key lies in identifying the element names for selection, which is shown in this tutorial video

If using 0 and nothing changes, try using a negative number.

Hope this helps!

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