Streamlit header

A header is a formatted text element that serves as a section title.
Streamlit headers help divide your app into logical sections.
 
 
Need a Streamlit developer? Click Here

Syntax

st.header(body, anchor=None, *, help=None, divider=False, width=”stretch”)
ParameterType / ValuesDescription
bodystrThe text to display as GitHub-flavored Markdown. Supports directives from st.markdown.
anchorstr, False, or NoneAnchor name for linking (#anchor in URL). If omitted, auto-generates from body. If False, no anchor is shown.
helpstr or NoneTooltip displayed next to the header. Supports GitHub-flavored Markdown. If None, no tooltip is shown.
dividerbool or str ("blue", "green", "orange", "red", "violet", "yellow", "gray"/"grey", "rainbow")Displays a divider below the header. • True: Cycles through colors (blue → green → orange …). • str: Sets divider color explicitly.
width"stretch", "content", or intDefines header width. • "stretch": Match parent width (default). • "content": Fit content width (max = parent). • int: Fixed pixel width (up to parent width).

Example 1

				
					import streamlit as st

st.header("_Streamlit_ is :blue[cool] :sunglasses:")

				
			

Example 2

				
					import streamlit as st
st.header("This is a header with a divider", divider="gray")
st.header("These headers have rotating dividers", divider=True)
st.header("One", divider=True)
st.header("Two", divider=True)
st.header("Three", divider=True)
st.header("Four", divider=True)

				
			

Example 3

Grouping sections with headers
Here, headers act like anchors for each workflow step.
				
					import streamlit as st

st.header("Upload Data")
st.file_uploader("choose file")

st.header("Preview Data")
st.dataframe({"Name": ["Alice", "Bob"], "Score": [85, 92]})


st.header("Analysis")
st.success("Model trained successfully!")


				
			

Example 4

Dynamic headers
Here, we change headers based on user input
				
					option = st.selectbox("Choose Section", ["Home", "About", "Contact"])

st.header(f"You selected: {option}")

				
			

Example 5

Conditional headers
				
					score = 80
if score > 90:
     st.header("🎉 Excellent Performance!")
else:
     st.header("📈 Keep Improving!")


				
			

Example 6

Inside Expanders
				
					with st.expander("See More"):
    st.header("Hidden Section")
    st.write("Content revealed inside.")


				
			

Example 7

Header with Icon
we can add icons to headers also.
				
					st.header("🔍 Data Exploration")
				
			

Summary

`Use headers to divide major sections (Overview, Analysis, Results)
Use subheaders for smaller subsections
Don’t overuse colors & emojis → keep it professional
Combine headers with layout (columns, expanders, tabs)`
 
 
 
Learn more about Strealit: Click Here
 
 
Watch Video’s on Streamlit:

Leave a Reply

Your email address will not be published. Required fields are marked *