--- productId: joy-ui title: React Aspect Ratio component components: AspectRatio --- # Aspect Ratio
The Aspect Ratio component resizes its contents to match the desired ratio.
{{"component": "@mui/docs/ComponentLinkHeader"}} ## Introduction Aspect Ratio is a wrapper component for quickly resizing content to conform to your preferred ratio of width to height. Media content like images can be stretched, resized, and cropped based on the CSS `object-fit` property. :::info A [native CSS `aspect-ratio` property](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/aspect-ratio) does exist, and we plan to implement it in Joy UI soon. ::: ## Basics ```jsx import AspectRatio from '@mui/joy/AspectRatio'; ``` The Aspect Ratio component wraps around the content that it resizes. The element to be resized must be the first direct child. The default ratio is `16/9`. {{"demo": "BasicRatio.js"}} ## Customization ### Variants The Aspect Ratio component supports Joy UI's four [global variants](/joy-ui/main-features/global-variants/): `solid`, `soft` (default), `outlined`, and `plain`. {{"demo": "VariantsRatio.js"}} :::info To learn how to add your own variants, check out [Themed components—Extend variants](/joy-ui/customization/themed-components/#extend-variants). Note that you lose the global variants when you add custom variants. ::: ### Ratio Use the `ratio` prop to change the aspect ratio, following the pattern `width/height`. For example, the demo below uses a ratio of `4/3`, which is a common alternative to the default `16/9`: {{"demo": "CustomRatio.js"}} :::info The `ratio` prop uses the [CSS `calc()`](https://developer.mozilla.org/en-US/docs/Web/CSS/calc) function under the hood. ::: ### Object fit When the content inside the Aspect Ratio component is an image or a video, you can use the `objectFit` prop to control how it's resized. This prop gives you access to all of the values associated with the CSS `object-fit` property: `cover` (default), `contain`, `fill`, `scaleDown`, `initial`, `inherit`, and `none`. {{"demo": "MediaRatio.js"}} ### Media placeholder Use a `