Hello all, I’m new to Streamlit and have recently started exploring multi-page apps. I had started with “streamlit-option-menu” and have moved on to the native “mulitpage apps”.
Even though the native feature is great, I kinda miss the look and feel that the option-menu brought. So, is there a way to style the multipages seen on the nav bar and make it look more like an option-menu, or maybe add my own CSS?
I’m a Streamlit newbie as well. I agree that the native multipage look and feel on the sidebar could do with some love. I will be using native multipage as it allows code to be organised better - my application UI will be quite big. If the Streamlit team read this, could I please second the wish for some styling options for mutlipages.
Icons (not emojis please!) will make it look more professional, and variable padding between the list of files as a bonus. Ideally an optional, thin rounded border as well as an accent colour for the background to differentiate it from the sidebar colour.
I do like the simple way of adding pages via a naming convention!
It’s not an ideal solution, because you may notice a small delay after the page loads before the changes actually happen, but you can adjust the margin and padding with some css like this
st.markdown(
"""
<style>
div[data-testid="stSidebarNav"] li div a {
margin-left: 1rem;
padding: 1rem;
width: 300px;
border-radius: 0.5rem;
}
div[data-testid="stSidebarNav"] li div::focus-visible {
background-color: rgba(151, 166, 195, 0.15);
}
</style>
""",
unsafe_allow_html=True,
)
Thanks for this. I did have a look at the generated HTML and noticed a few IDs and what looked to me like dynamically generated CSS classes, so was unsure what would be “sticky” enough to have a go at targeting via st.markdown. Anyway, it would take me time to figure out the structure of the Streamlit HTML.
So thanks for showing me that the “stSidebarNav” is a static ID and your solution looks like a great start. I will go and try this out.
Trying the code worked, but in a multipage app switching pages caused the side nav bar to move as you pointed out. By removing the positioning attributes this cleared that issue. My first attempt is close but no cigar! I’ll keep learning as I go.
Note that, if you use this solution, you will need to add the styling to every page in your multipage app. I would recommend making a function that adds this css, and then importing and calling that function from within every page.
Sure, I did have the styling on each page. Unfortunately, with the padding/margin code it was too janky for use. The repositioning of the elements was clearly visible (I have everything running locally on a fast machine).
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.