What is aspect-ratio in CSS?
aspect-ratio is a CSS property that sets a fixed relationship between an element's width and height. The ratio expresses the proportion between the two dimensions: a 16/9 ratio means 16 units of width for every 9 units of height. It is very useful for controlling visual rendering and guaranteeing that elements keep their shape at any screen size.
By default, an element's dimensions are often determined independently, which can lead to distortion when the width or height changes. aspect-ratio fixes that by imposing a proportional relationship the browser must respect when rendering.



























































































































Unlimited requests, fast results
Submit as many briefs as you need. Our plans allow you to manage a continuous flow of design requests, without limits and without friction, and at an economic cost.
Why use aspect-ratio?
aspect-ratio is especially important for media content such as images, videos and canvases, where proportions must stay constant to avoid visual distortion. A 16:9 video, for example, has to keep that ratio even as its width tracks the window size.
In responsive design, where element sizes adapt to the viewport, the property guarantees elements keep their original proportions without complicated CSS tricks (such as padding hacks).
Some of the benefits:
- Prevents images and videos from being distorted.
- Simplifies handling of square, rectangular or other shaped blocks.
- Automatically manages the height when only the width is known or set (and vice versa).
- Improves performance by avoiding complex dimension recalculations.
How to use the aspect-ratio property
The CSS aspect-ratio property takes a numeric ratio in the form:
Common examples:
The browser automatically computes the missing dimension to honour the ratio whenever one of the two dimensions is set (either width or height). If only width is fixed, for instance, the height is derived from the ratio.
Compatibility and best practices
aspect-ratio is supported natively by the vast majority of modern browsers, including Chrome, Firefox, Edge and Safari. It is relatively recent (around 2021), so it can be worth checking compatibility for older browsers or specific devices.
In the meantime, alternatives such as percentage-based padding-top are still used in some projects to simulate the behavior.
Best practices:
- Use
aspect-ratiowhenever possible to simplify your code and improve readability. - For media elements, always set a ratio consistent with the original content.
- Combine it with flexible properties such as
max-widthormax-heightfor optimal responsive rendering. - Always test across platforms to avoid unexpected results.



























































































































Unlimited requests, fast results
Submit as many briefs as you need. Our plans allow you to manage a continuous flow of design requests, without limits and without friction, and at an economic cost.
Concrete use cases for aspect-ratio
A few examples where aspect-ratio proves very useful:
- Responsive images: guarantee images resize without distortion as the screen size changes.
- Embedded video: keep a 16/9 or 4/3 ratio whatever the container.
- Placeholders and UI cards: build preview blocks and display cards that keep their proportions regardless of content or screen.
- Canvas: set the size in pixels while keeping a proportional display.
- Grids and galleries: create grids where every cell shares the same ratio, making alignment effortless.
Thanks to aspect-ratio, front-end development gets simpler: fewer convoluted CSS tricks and more robust, fluid interfaces.
Key takeaways
- Aspect-ratio in brief:
- Simple definition: aspect-ratio in CSS is the width-to-height ratio of an element.
- Main purpose: keeps the proportions of a block, image or video constant whatever the display context.
- Syntax: you declare a ratio, for example aspect-ratio: 16 / 9;.
- Layout impact: makes responsive layouts easier by preventing distortion and content jumps.
Unlimited requests, fast results
Submit as many briefs as you like. Our plans let you manage a continuous flow of design requests, without limits or friction, and at an economical price.