How to use Material UI’s Skeleton component

Key takeaways:

  • Material UI is a popular React component library that follows Google's Material Design guidelines to build visually appealing, responsive web apps.

  • Skeleton component is a visual placeholder that improves user experience during content loading by preventing blank screens.

  • Skeleton has four variants—text, circular, rectangular, and rounded—for different types of placeholders.

  • Skeleton components have a default pulsating animation, but you can change it to a wave or disable it entirely using the animation prop.

  • Skeleton components can automatically adjust their size based on their parent element, maintaining layout consistency.

Material UI is a popular open-source library that provides pre-designed components and styles for building modern and visually appealing web applications. Material UI follows the guidelines provided by Google’s Material Design resulting in intuitive and well-designed components.

In this Answer, we will look into how we can use Material UI's Skeleton component in a React application and increase user experience.

Note: Please makes sure to install Material UI version 5 in your systems as we will be using it in the Answer.

The Skeleton component

The Skeleton component acts as a visual placeholder while the content is loading on the screen. This helps improve user experience by reducing load time frustration, and ensuring responsiveness and activity while avoiding a blank white screen. To get a clear idea of how a Skeleton component looks visually, refer to the following illustration:

Visual illustration of a Skeleton component
Visual illustration of a Skeleton component

Skeleton variants

The Skeleton component has four different shape variants that can be used depending on the use case:

  • text: It is the default variant that represents a single textual line. Its height can be adjusted using the font size attribute.

  • circular: It is usually used when loading thumbnails, icons, or avatars on the web page.

  • rectangular: It displays rectangular-shaped placeholders like paragraphs, images, or any rectangular element.

  • rounded: It displays rectangular placeholders with rounded corners.

The code to use each variant is shown below:

body {
  font-family: sans-serif;
  -webkit-font-smoothing: auto;
  -moz-font-smoothing: auto;
  -moz-osx-font-smoothing: grayscale;
  font-smoothing: auto;
  text-rendering: optimizeLegibility;
  font-smooth: always;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

h1 {
  font-size: 1.5rem;
}
Variants of Skeleton component

In the above output, the first is the rectangular variant, followed by the circular, text, and rounded variants.

Code explanation

  • Line 4: We import the Skeleton component from @mui/material/Skeleton.

  • Line 10: We define the Skeleton component with the variant attribute set to rectangular and specify its height.

  • Line 12: We define the Skeleton component with the variant attribute set to circular and specify its width and height.

  • Line 13: We define the Skeleton component with the variant attribute set to text.

  • Line 14: We define the Skeleton component with the variant attribute set to rounded.

Skeleton animations

The Skeleton component provides us with pulsating animations by default, but we can change it to a wave animation or just remove it entirely. The coding example for changing animations is given below:

body {
  font-family: sans-serif;
  -webkit-font-smoothing: auto;
  -moz-font-smoothing: auto;
  -moz-osx-font-smoothing: grayscale;
  font-smoothing: auto;
  text-rendering: optimizeLegibility;
  font-smooth: always;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

h1 {
  font-size: 1.5rem;
}
Animations in Skeleton components

In the output above, we see that the first Skeleton placeholder has a wave animation, the circular placeholder’s animation is disabled, and the last two placeholders are, by default, pulsating.

Code explanation

  • Line 10: We define the Skeleton component and set the animation attribute to wave.

  • Line 12: We define the Skeleton component and disable animation by setting the animation attribute to false.

Skeleton automatic resizing

The Skeleton components can infer the size of the component it is placed in and resize itself. The coding example of Skeleton components resizing automatically by inferring the dimensions is given below:

Bud1		x.jsIloc	index.jsIlocblob�.������package.jsonIlocblob.������publicIlocblob�.������srcIlocblob�$������srclg1ScompsrcmoDDblob��깬��AsrcmodDblob��깬��Asrcph1Scomp
styles.cssIlocblob�.������ @� @� @� @E	DSDB `� @� @� @
Automatic sizing and coloring of Skeleton components

In the output above, we can see that the first placeholder infers the dimensions of the Typography component in which it is placed and adjusts its size to the size of a h1 text. Similarly, the rest of the placeholders adjust their size according to the Typography variant they are placed in. The code explanation is given below:

Code explanation

  • Line 12: We place the Skeleton component inside the Typography component of h1 variant.

  • Line 15: We place the Skeleton component inside the Typography component of h2 variant.

  • Line 18: We place the Skeleton component inside the Typography component of h4 variant. To change the color of the Skeleton component, we can use the sx attribute and give a bgcolor.

Real-world example (YouTube videos) of Skeleton

In the coding example below, we have replicated how placeholders are displayed when we navigate to the YouTube home page. Click the “Run” button below and wait for 5 seconds so the video loads and the placeholder disappears.

Bud1		x.jsIloc	index.jsIlocblob�.������package.jsonIlocblob.������publicIlocblob�.������srcIlocblob�������srclg1ScompsrcmoDDblob;E����AsrcmodDblob;E����Asrcph1Scomp
styles.cssIlocblob�.������ @� @� @� @E	DSDB `� @� @� @
Use case of Skeleton components

Code explanation

  • Line 10: We have defined a setTimeout function that changes the state of the loading state variable to false after 5 seconds.

  • Line 13: We have defined a ternary operator that checks if the loading state is true and displays the Skeleton components (placeholders) from lines 34–38. Otherwise, we show the contents of the loaded video (lines 15–32).

Explore the following projects for hands-on practice in creating real-world applications with React. You can enhance these projects by incorporating Material-UI for a polished and visually appealing design.

Conclusion

The Material UI Skeleton component provides temporary visual placeholders for content loading and enhancing user experience. By using placeholders, the design consistency is maintained while data is being fetched.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


What is Skeleton in material UI?

The Skeleton component in Material UI is a placeholder that mimics the shape and size of content while it is loading. It helps improve user experience by reducing perceived load times and preventing a blank screen.


How do I import components from material UI?

We can import components from Material UI in the following way:

import { Button } from '@mui/material';

What is skeleton feedback?

The Skeleton feedback is a Material UI component that displays animated placeholders while data is loading or being fetched, providing a preview until the content is ready.


When should you use Skeleton vs. Spinner?

  • Use Skeleton when you want to show a placeholder layout (e.g., for images, text, or lists) to maintain the design while content loads.
  • Use Spinner when you want to show a loading indicator, usually for tasks that take a short time to process or require ongoing feedback (e.g., submitting a form or processing a request).

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved