--- productId: material-ui title: React Skeleton component components: Skeleton githubLabel: 'scope: skeleton' githubSource: packages/mui-material/src/Skeleton --- # Skeleton Display a placeholder preview of your content before the data gets loaded to reduce load-time frustration. The data for your components might not be immediately available. You can improve the perceived responsiveness of the page by using skeletons. It feels like things are happening immediately, then the information is incrementally displayed on the screen (Cf. [Avoid The Spinner](https://www.lukew.com/ff/entry.asp?1797)). ## Usage The component is designed to be used **directly in your components**. For instance: ```jsx { item ? ( {item.title} ) : ( ); } ``` ## Variants The component supports 4 shape variants: - `text` (default): represents a single line of text (you can adjust the height via font size). - `circular`, `rectangular`, and `rounded`: come with different border radius to let you take control of the size. ```tsx import Skeleton from '@mui/material/Skeleton'; import Stack from '@mui/material/Stack'; export default function Variants() { return ( {/* For variant="text", adjust the height via font-size */} {/* For other variants, adjust the size with `width` and `height` */} ); } ``` ## Animations By default, the skeleton pulsates, but you can change the animation to a wave or disable it entirely. ```tsx import Box from '@mui/material/Box'; import Skeleton from '@mui/material/Skeleton'; export default function Animations() { return ( ); } ``` ### Pulsate example ```tsx import Grid from '@mui/material/Grid'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; import Skeleton from '@mui/material/Skeleton'; const data = [ { src: 'https://i.ytimg.com/vi/pLqipJNItIo/hqdefault.jpg?sqp=-oaymwEYCNIBEHZIVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLBkklsyaw9FxDmMKapyBYCn9tbPNQ', title: 'Don Diablo @ Tomorrowland Main Stage 2019 | Official…', channel: 'Don Diablo', views: '396k views', createdAt: 'a week ago', }, { src: 'https://i.ytimg.com/vi/_Uu12zY01ts/hqdefault.jpg?sqp=-oaymwEZCPYBEIoBSFXyq4qpAwsIARUAAIhCGAFwAQ==&rs=AOn4CLCpX6Jan2rxrCAZxJYDXppTP4MoQA', title: 'Queen - Greatest Hits', channel: 'Queen Official', views: '40M views', createdAt: '3 years ago', }, { src: 'https://i.ytimg.com/vi/kkLk2XWMBf8/hqdefault.jpg?sqp=-oaymwEYCNIBEHZIVfKriqkDCwgBFQAAiEIYAXAB&rs=AOn4CLB4GZTFu1Ju2EPPPXnhMZtFVvYBaw', title: 'Calvin Harris, Sam Smith - Promises (Official Video)', channel: 'Calvin Harris', views: '130M views', createdAt: '10 months ago', }, ]; interface MediaProps { loading?: boolean; } function Media(props: MediaProps) { const { loading = false } = props; return ( {(loading ? Array.from(new Array(3)) : data).map((item, index) => ( {item ? ( {item.title} ) : ( )} {item ? ( {item.title} {item.channel} {`${item.views} • ${item.createdAt}`} ) : ( )} ))} ); } export default function YouTube() { return ( ); } ``` ### Wave example ```tsx import * as React from 'react'; import Card from '@mui/material/Card'; import CardHeader from '@mui/material/CardHeader'; import CardContent from '@mui/material/CardContent'; import CardMedia from '@mui/material/CardMedia'; import Avatar from '@mui/material/Avatar'; import Typography from '@mui/material/Typography'; import IconButton from '@mui/material/IconButton'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import Skeleton from '@mui/material/Skeleton'; interface MediaProps { loading?: boolean; } function Media(props: MediaProps) { const { loading = false } = props; return ( ) : ( ) } action={ loading ? null : ( ) } title={ loading ? ( ) : ( 'Ted' ) } subheader={ loading ? ( ) : ( '5 hours ago' ) } /> {loading ? ( ) : ( )} {loading ? ( ) : ( { "Why First Minister of Scotland Nicola Sturgeon thinks GDP is the wrong measure of a country's success:" } )} ); } export default function Facebook() { return (
); } ``` ## Inferring dimensions In addition to accepting `width` and `height` props, the component can also infer the dimensions. It works well when it comes to typography as its height is set using `em` units. ```jsx {loading ? : 'h1'} ``` ```tsx import Typography, { TypographyProps } from '@mui/material/Typography'; import Skeleton from '@mui/material/Skeleton'; import Grid from '@mui/material/Grid'; const variants = [ 'h1', 'h3', 'body1', 'caption', ] as readonly TypographyProps['variant'][]; function TypographyDemo(props: { loading?: boolean }) { const { loading = false } = props; return (
{variants.map((variant) => ( {loading ? : variant} ))}
); } export default function SkeletonTypography() { return ( ); } ``` Use `variant="text"` when inferring dimensions from typography, and customize the border radius with the `sx` prop if you need a different shape while preserving typography-based sizing. But when it comes to other components, you may not want to repeat the width and height. In these instances, you can pass `children` and it will infer its width and height from them. ```jsx loading ? ( ) : ( ); ``` ```tsx import { styled } from '@mui/material/styles'; import Box from '@mui/material/Box'; import Typography from '@mui/material/Typography'; import Avatar from '@mui/material/Avatar'; import Grid from '@mui/material/Grid'; import Skeleton from '@mui/material/Skeleton'; const Image = styled('img')({ width: '100%', }); function SkeletonChildrenDemo(props: { loading?: boolean }) { const { loading = false } = props; return (
{loading ? ( ) : ( )} {loading ? ( . ) : ( Ted )} {loading ? (
) : ( )}
); } export default function SkeletonChildren() { return ( ); } ``` ## Color The color of the component can be customized by changing its `background-color` CSS property. This is especially useful when on a black background (as the skeleton will otherwise be invisible). ```tsx import Skeleton from '@mui/material/Skeleton'; import Box from '@mui/material/Box'; export default function SkeletonColor() { return ( ); } ``` ## Accessibility Skeleton screens provide an alternative to the traditional spinner method. Rather than showing an abstract widget, skeleton screens create anticipation of what is to come and reduce cognitive load. The background color of the skeleton uses the least amount of luminance to be visible in good conditions (good ambient light, good screen, no visual impairments). ### ARIA None. ### Keyboard The skeleton is not focusable. # Skeleton API ## Demos For examples and details on the usage of this React component, visit the component demo pages: - [Skeleton](https://mui.com/material-ui/react-skeleton/) ## Import ```jsx import Skeleton from '@mui/material/Skeleton'; // or import { Skeleton } from '@mui/material'; ``` ## Props | Name | Type | Default | Required | Description | |------|------|---------|----------|-------------| | animation | `'pulse' \| 'wave' \| false` | `'pulse'` | No | | | children | `node` | - | No | | | classes | `object` | - | No | Override or extend the styles applied to the component. | | component | `elementType` | - | No | | | height | `number \| string` | - | No | | | sx | `Array \| func \| object` | - | No | The system prop that allows defining system overrides as well as additional CSS styles. | | variant | `'circular' \| 'rectangular' \| 'rounded' \| 'text' \| string` | `'text'` | No | | | width | `number \| string` | - | No | | > **Note**: The `ref` is forwarded to the root element (HTMLSpanElement). > Any other props supplied will be provided to the root element (native element). ## Theme default props You can use `MuiSkeleton` to change the default props of this component with the theme. ## CSS ### Rule name | Global class | Rule name | Description | |--------------|-----------|-------------| | - | circular | Styles applied to the root element if `variant="circular"`. | | - | fitContent | Styles applied when the component is passed children and no width. | | - | heightAuto | Styles applied when the component is passed children and no height. | | - | pulse | Styles applied to the root element if `animation="pulse"`. | | - | rectangular | Styles applied to the root element if `variant="rectangular"`. | | - | root | Styles applied to the root element. | | - | rounded | Styles applied to the root element if `variant="rounded"`. | | - | text | Styles applied to the root element if `variant="text"`. | | - | wave | Styles applied to the root element if `animation="wave"`. | | - | withChildren | Styles applied when the component is passed children. | ## Source code If you did not find the information on this page, consider having a look at the implementation of the component for more detail. - [/packages/mui-material/src/Skeleton/Skeleton.js](https://github.com/mui/material-ui/tree/HEAD/packages/mui-material/src/Skeleton/Skeleton.js)