st.columns() in Streamlit

The columns method in Streamlit is used to create multiple columns in a single row — perfect for building side-by-side layouts such as dashboards, forms, or comparison views.

It helps organize elements horizontally instead of vertically.

Syntax

st.columns(spec, *, gap="small")    

The function has the following parameters:

Example: Create 3 equal columns.

Python

# Importing the Streamlit library
import streamlit as st

st.title("st.columns Example")

# Create 3 equal-width columns
col1, col2, col3 = st.columns(3)

# Add content to each column
col1.header("Column 1")
col1.write("This is the first column")

col2.header("Column 2")
col2.write("This is the second column")

col3.header("Column 3")
col3.write("This is the third column")    

The output of the above code is shown below:

Columns in Streamlit

Example: Different Widths

Python

# Importing the Streamlit library
import streamlit as st

st.title("Custom Width Columns")

# Create columns with relative widths
col1, col2, col3 = st.columns([3, 1, 2])

col1.header("Column 1")
col1.write("Takes 3 parts of width")

col2.header("Column 2")
col2.write("Takes 1 part of width")

col3.header("Column 3")
col3.write("Takes 2 parts of width")    

The output of the above code is shown below:

Columns in Streamlit