Embedding CSS and HTML leaves white space in the page

Embedding CSS and HTML in the page leaves white space, while it should have height=0.
This changes the page global format.

Here I would expect that the space between text2 and text3, and the space between text3 and text4 are the same as the one between text1 and text2:

Is there a way to hide this embedded code?
Changing the margins and paddings of element-container cannot be done because the rest of the code would completely change its proportions. Of course if it was possible to assign a class or id to st.markdown and st.components would have easily solved the issue…

import streamlit as st

st.write("text2: nothing between text1 and text2")
css = '''
        button {
            background-color: yellow;
st.markdown(css, unsafe_allow_html=True)
st.write("text3: 'invisible' st.markdown embedded between text2 and text3")
js = f'''
        console.log("This is a console.log line");
st.components.v1.html(js, width=0, height=0)
st.write("text4: 'invisible' st.components embedded between text3 and text4")

html = '''<hr>'''
st.markdown(html, unsafe_allow_html=True)
st.write("A button to show the style added after text2")
html = '''<button type="button">This is a styled button</button>'''
st.markdown(html, unsafe_allow_html=True)

Hi @Nemecsek

Thank for sharing.

Add all the CSS and JS at the end.

Alas it is not possible in some cases to put everything at the end of the page.
I needed some HTML components at the top of the page and that’s when I found out this issue.

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