Aspect-Ratio Property

Last updated: 2026-09-13

aspect-ratio Aspect-Ratio Property

The aspect-ratio property forces an element to keep a fixed width-to-height ratio, eliminating the need for the old padding-percentage hack. Its default value, auto, uses the element's intrinsic ratio, as with images. It is a relatively new CSS feature that greatly simplifies responsive containers for video and cards.

Category
Initial Valueauto
InheritedNo
Applies Toall
Animation Typelength
CSS VersionCSS3
StatusStandard

📝 Syntax

aspect-ratio: auto || <ratio>;

⚙️ Values

ValueTypeDescription
autoKeywordUse the element's intrinsic aspect ratio.
<ratio>TypeA specified aspect ratio, such as 16/9.

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
aspect-ratio v88 v88 v89 v15 v74
Supported in all major browsers
Tip: Pairing aspect-ratio with width:100% creates an adaptive proportional container, often used for embedded video and images.

❓ FAQ

QWhat's the difference between aspect-ratio and the padding-top hack?
ABoth create proportional containers, but aspect-ratio is a native property, which is more readable and easier to maintain. The padding-top hack uses a percentage padding relative to width to push out the height, typically with a ::before pseudo-element and absolutely positioned content, which is fiddly. aspect-ratio does the job in one line, so it is the recommended choice for new projects.
QDoes height still work when aspect-ratio is set?
Aaspect-ratio computes the height from an already determined width; if you also set height explicitly, that explicit height wins and overrides the ratio-computed height, so the ratio is no longer guaranteed. To keep the ratio enforced, do not set height; set only width and aspect-ratio. Also note that auto means the element's intrinsic ratio, such as an image's original dimensions.
QWhy isn't aspect-ratio working?
ACommon causes: first, the element also has a height set, and an explicit height takes priority; second, the element has no width, with width:auto and no content, leaving the ratio nothing to work from; third, the browser is too old, since the property gained stable support in Chrome 88, Firefox 89, and Safari 15. When debugging, first confirm the width and height state and give the element a width such as width:100%.
QHow do I build a responsive video container with aspect-ratio?
ASet width:100%; aspect-ratio:16/9 on the container. As the parent's width changes, the height is computed automatically to preserve the ratio, so the box scales proportionally; then absolutely position an iframe or video inside to fill it. This replaces the padding-top hack entirely. For images, preset aspect-ratio on an img container to reduce layout shift (CLS) while the image loads, which measurably improves Core Web Vitals.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏