Why does Streamlit render multiple spaces as a single space?

Sometimes I want to use multiple spaces in strings for cosmetic reasons. But Streamlit will always turn multiple spaces into a single space.

Why? Any ideas on how to disable / workaround?

Thanks :smiling_face:

Streamlit is probably parsing your string as markdown. Is st.text() what you are looking for?

Ah ok that makes sense. But, I am trying to arrange things in an st.info box, but it is only seeing it as markdown, and going st.info(st.text("spaces ")) (unsurprisingly) doesnโ€™t work.

Then you have to learn how to tell markdown to format the text as you want. For example using blocks of preformatted text.

s = """
Normal text m
```
preformatted text        text after spaces
    indented text
```
More normal text
"""

st.info(s)

4 Likes

Thanks for that @Goyo, amazing :smiling_face_with_three_hearts:

Btw. in st.info you can use   to add space. It works on our forum as well: "    " = "ย ย ย ย "

1 Like