` or `Box` component to center the content.
+
+{{"demo": "PlaceholderAspectRatio.js"}}
+
## Controlling the height
Use `minHeight` and `maxHeight` to set the lower and upper bound of the component's height.
@@ -48,6 +54,31 @@ When the aspect ratio component is placed as a child of a flexbox `row` containe
{{"demo": "FlexRowRatio.js"}}
+## Integration
+
+### Next.js Image
+
+The `AspectRatio` component can be used with [Next.js Image](https://nextjs.org/docs/basic-features/image-optimization) component.
+
+```js
+import Image from 'next/image';
+import AspectRatio from '@mui/joy/AspectRatio';
+import mountains from '../public/mountains.jpg';
+
+function App() {
+ return (
+
+ {/* only layout="fill" makes sense for using with AspectRatio */}
+
+
+ );
+}
+```
+
+:::info
+Always use `layout="fill"` on the image component, otherwise you don't need to use aspect ratio because the height is based on the image.
+:::
+
## Common examples
### Mobile Carousel
diff --git a/packages/mui-joy/src/AspectRatio/AspectRatio.tsx b/packages/mui-joy/src/AspectRatio/AspectRatio.tsx
index a291861e1a0864..bac509a49835f6 100644
--- a/packages/mui-joy/src/AspectRatio/AspectRatio.tsx
+++ b/packages/mui-joy/src/AspectRatio/AspectRatio.tsx
@@ -59,7 +59,11 @@ const AspectRatioContent = styled('div', {
paddingBottom: 'var(--AspectRatio-paddingBottom)',
overflow: 'hidden',
// use data-attribute instead of :first-child to support zero config SSR (emotion)
- '& > [data-first-child]': {
+ // use nested selector for integrating with nextjs image (spans are inserted on top of the img)
+ '& [data-first-child]': {
+ display: 'flex',
+ justifyContent: 'center',
+ alignItems: 'center',
boxSizing: 'border-box',
position: 'absolute',
width: '100%',