Skip to content

st.metric with chart_data wraps unexpectedly in horizontal containers #13785

@arnaudmiribel

Description

@arnaudmiribel

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

When using st.metric with sparklines (chart_data) inside st.container(horizontal=True), the metrics sometimes wrap to take up full rows instead of staying side-by-side. The behavior is non-deterministic and seems related to the interaction between chart sizing and flex layout.

Reproducible Code Example

import streamlit as st

with st.container(horizontal=True):
    st.metric("Revenue", "$1.2M", "+12%", border=True, chart_data=[1,2,3,4,5,6,7], chart_type="line")
    st.metric("Orders", "11k", "+8%", border=True, chart_data=[3,1,4,1,5,9,2], chart_type="bar")
    st.metric("Customers", "8.5k", "+15%", border=True, chart_data=[2,3,2,4,3,5,4], chart_type="line")
    st.metric("AOV", "$132", "+3%", border=True)

Steps To Reproduce

No response

Expected Behavior

All metrics stay in a single row.

Image

Current Behavior

Metrics wrap to full-width rows (second screenshot). Behavior varies on page load/resize.

Image

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.53.1
  • Python version:
  • Operating System: Apple
  • Browser: Chrome

Additional Information

No response

Metadata

Metadata

Assignees

Labels

feature:st.containerRelated to the `st.container` elementfeature:st.metricRelated to the `st.metric` elementpriority:P2Medium-high priority - fix within one monthstatus:confirmedBug has been confirmed by the Streamlit teamtype:bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions