Skills

Using Streamlit Layouts

Structuring Streamlit app layouts.

Install

npx skills add iusztinpaul/designing-real-world-ai-agents-workshop --skill using-streamlit-layouts -g -a claude-code -y
Category
Engineering
Updated
5mo ago
License
Apache-2.0
Context cost
Lightabout 1,343 tokens
Runs scripts
No, instructions only

What it does

Structuring Streamlit app layouts. Use when placing content in sidebars, columns, containers, or dialogs. Covers sidebar usage, column limits, horizontal containers, dialogs, and bordered cards.

Streamlit layout

How you structure your app affects usability more than you think.

Sidebar: navigation + global filters only

The sidebar should only contain navigation and app-level filters. Main content goes in the main area.

# GOOD
with st.sidebar:
    date_range = st.date_input("Date range")
    region = st.selectbox("Region", ["All", "US", "EU", "APAC"])
    st.caption("App v1.2.3")
# BAD: Too much content in sidebar
with st.sidebar:
    st.title("Dashboard")
    st.dataframe(df)  # Don't put main content here
    st.bar_chart(data)

What goes in sidebar:

  • Global filters (date range, user selection, region)
  • App info (version, feedback link)

What stays out:

  • Main content, charts, tables, results

Columns: max 4, set alignment

Don't use too many columns, they get cramped.

# GOOD
col1, col2 = st.columns(2)

# Custom widths (ratios)
col1, col2 = st.columns([2, 1])  # 2:1 ratio

# OK with alignment
cols = st.columns(4, vertical_alignment="center")

# BAD: Too many, cramped
col1, col2, col3, col4, col5, col6 = st.columns(6)

Horizontal containers for button groups

Use st.container(horizontal=True) instead of columns for button groups:

with st.container(horizontal=True):
    st.button("Cancel")
    st.button("Save")
    st.button("Submit")

Aligning elements

Use horizontal_alignment on containers to position elements:

# Center elements
with st.container(horizontal_alignment="center"):
    st.image("logo.png", width=200)
    st.title("Welcome")

# Right-align elements
with st.container(horizontal_alignment="right"):
    st.button("Settings", icon=":material/settings:")

# Distribute evenly (great for button groups)
with st.container(horizontal=True, horizontal_alignment="distribute"):
    st.button("Cancel")
    st.button("Save")
    st.button("Submit")

Options: "left" (default), "center", "right", "distribute"

Bordered containers

Read the whole SKILL.md on GitHub

More in Engineering