How to indent bullet point list items?

There’s an old question on this topic but the self-answer involved a broken link to Google’s natural language docs.

I figured out how to make bullet points with st.markdown() but I can’t figure out how to indent them.

st.write(“The following list won’t indent no matter what I try:”)
st.markdown(“- Item 1”)
st.markdown(“- Item 2”)
st.markdown(“- Item 3”)

Seems the main Docs entry doesn’t show anything except bold and italics. Elsewhere the Docs mention Github Flavored Markdown (GFM) but it’s confusing because those span multiple lines in a way not supported by st.markdown() and also when I try any of the symbols from GFM like > it doesn’t work.

Python==3.9
streamlit==1.11.0

You can use css to indent ul.

import streamlit as st

st.write("The following list won’t indent no matter what I try:")
st.markdown("- Item 1")
st.markdown("- Item 2")
st.markdown("- Item 3")

st.markdown('''
<style>
[data-testid="stMarkdownContainer"] ul{
    list-style-position: inside;
}
</style>
''', unsafe_allow_html=True)

or:

import streamlit as st

st.write("The following list won’t indent no matter what I try:")
st.markdown("- Item 1")
st.markdown("- Item 2")
st.markdown("- Item 3")

st.markdown('''
<style>
[data-testid="stMarkdownContainer"] ul{
    padding-left:40px;
}
</style>
''', unsafe_allow_html=True)

1 Like

Thank you! That’s very helpful. Now it makes more sense.

Alternatively, there’s also the much simpler approach:

st.markdown(
"""
The following list won't indent no matter what I try:
- Item 1
- Item 2
- Item 3
"""
)

image

1 Like

I can not ident ul items use your method.It is strange.

1 Like

Oh yes that’s very helpful. Thanks for showing me this syntax.

Update - perhaps I’m doing something wrong, but this latter method is actually not indenting for me. Does it need extra spaces to indicate that it should be indented?

Ah, it works if I use it in combination with the earlier CSS.

1 Like

Hey all :wave: Apologies for the confusion. I didn’t realize I had @ji_haoran’s CSS hack pasted at the bottom of my code. @hack-r you’re right that the indentation works only in combination with the earlier CSS. This is likely a bug and you could submit an issue on GitHub about it.

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