st.skeleton
Display a skeleton loading placeholder.
A skeleton is an animated placeholder that indicates content is loading. Use it to reserve layout space and provide visual feedback while content loads. It can be used in two ways:
Standalone mode (like st.empty()): Returns a placeholder that is shown immediately and can be replaced with content later by calling an st.* method on it (for example, placeholder.dataframe(...)).
Context manager mode (like st.spinner(), recommended): The skeleton is shown while the with block runs (after a short delay) and automatically clears when the block exits, whether normally or due to an exception. Like st.spinner, any st.* calls made inside the with block are written to the parent container and remain visible after the skeleton clears.
Note
Context manager mode is recommended. Use standalone mode only when you need to reserve a slot and fill it later (like st.empty()).
| Function signature[source] | |
|---|---|
st.skeleton(height=None, *, width="stretch") | |
| Parameters | |
height (int, "stretch", or None) | The height of the skeleton. This can be one of the following:
|
width (int or "stretch") | The width of the skeleton. This can be one of the following:
|
| Returns | |
(SkeletonPlaceholder) | A placeholder object that can be used to replace the skeleton with other content, or as a context manager. |
Examples
Standalone mode - replace skeleton with content:
import streamlit as st import time placeholder = st.skeleton(height=200) time.sleep(2) placeholder.dataframe({"col1": [1, 2, 3], "col2": [4, 5, 6]})
Context manager mode - skeleton auto-clears when block exits:
import streamlit as st import time with st.skeleton(height=100): # Expensive computation runs here time.sleep(2) # Skeleton clears, show results below st.success("Data loaded!")
Still have questions?
Our forums are full of helpful information and Streamlit experts.