Show API reference for

Display text in header formatting.

Function signature[source]

st.header(body, anchor=None, *, help=None, icon=None, divider=False, width="stretch", text_alignment="left", wrap=True)

Parameters

body (str)

The text to display as GitHub-flavored Markdown. Syntax information can be found at: https://github.github.com/gfm.

See the body parameter of st.markdown for additional, supported Markdown directives.

anchor (str or False)

The anchor name of the header that can be accessed with #anchor in the URL. If omitted, it generates an anchor using the body. If False, the anchor is not shown in the UI.

help (str or None)

A tooltip that gets displayed next to the header. If this is None (default), no tooltip is displayed.

The tooltip can optionally contain GitHub-flavored Markdown, including the Markdown directives described in the body parameter of st.markdown.

icon (str or None)

An optional emoji or icon to display next to the header. If icon is None (default) or "", no icon is displayed. Empty string is accepted so you can pass page.icon when a page has no icon. If icon is a non-empty string, the following options are valid:

  • A single-character emoji. For example, you can set icon="🚨" or icon="🔥". Emoji short codes are not supported.

  • An icon from the Material Symbols library (rounded style) in the format ":material/icon_name:" where "icon_name" is the name of the icon in snake case.

    For example, icon=":material/thumb_up:" will display the Thumb Up icon. Find additional icons in the Material Symbols font library.

  • "spinner": Displays a spinner as an icon.

The icon is decorative: it is not included in the heading's accessible name and does not affect the auto-generated anchor.

divider (bool, "blue", "green", "orange", "red", "violet", "yellow", "gray"/"grey", or "rainbow")

Shows a colored divider below the header. If this is True, successive headers will cycle through divider colors, except gray and rainbow. That is, the first header will have a blue line, the second header will have a green line, and so on. If this is a string, the color can be set to one of the following: blue, green, orange, red, violet, yellow, gray/grey, or rainbow.

width ("stretch", "content", or int)

The width of the header element. This can be one of the following:

  • "stretch" (default): The width of the element matches the width of the parent container.
  • "content": The width of the element matches the width of its content, but doesn't exceed the width of the parent container.
  • An integer specifying the width in pixels: The element has a fixed width. If the specified width is greater than the width of the parent container, the width of the element matches the width of the parent container.

text_alignment ("left", "center", "right", or "justify")

The horizontal alignment of the text within the element. This can be one of the following:

  • "left" (default): Text is aligned to the left edge.
  • "center": Text is centered.
  • "right": Text is aligned to the right edge.
  • "justify": Text is justified (stretched to fill the available width with the last line left-aligned).

Note

For text alignment to have a visible effect, the element's width must be wider than its content. If you use width="content" with short text, the alignment may not be noticeable.

wrap (bool)

Whether the header can wrap onto multiple lines. This can be one of the following:

  • True (default): If the header is too wide for the element, it wraps onto additional lines.
  • False: The header stays on one line. Overflow is truncated with an ellipsis. Extra body lines after the first newline are omitted so the heading stays one line. Anchor and help icons remain visible.

Examples

import streamlit as st

st.header("_Streamlit_ is :blue[cool] :sunglasses:")
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)
st.header("Header with an icon", icon=":material/home:")
star

Tip

Want a new st.header feature or found a bug? Browse open issues and react with a 👍 on the initial post of the ones that matter to you. Your votes help us prioritize what to work on next.

forum

Still have questions?

Our forums are full of helpful information and Streamlit experts.