DevBolt
Processed in your browser. Your data never leaves your device.

CSS aspect-ratio Property Guide

The CSS aspect-ratio property defines the preferred width-to-height ratio of an element. It replaced the padding-top hack for responsive containers and is now supported in all modern browsers.

Home/Aspect Ratio Calculator

Aspect Ratio Calculator

Calculate, convert, and resize aspect ratios for images, video, and responsive design.

Enter Dimensions

Result

16:9
Aspect Ratio
1.7778
Decimal
1920 × 1080
aspect-ratio: 16 / 9;

Common Aspect Ratios

Equivalent Sizes at 16:9

WidthHeightPixelsLabel
3201800.1 MP
4802700.1 MP
6403600.2 MP
7684320.3 MP
9605400.5 MP
10245760.6 MP
12807200.9 MP720p / HD
14408101.2 MP
16009001.4 MP
192010802.1 MP1080p / Full HD
256014403.7 MP1440p / 2K
384021608.3 MP2160p / 4K UHD

Syntax and basic usage

The property accepts a ratio: aspect-ratio: 16 / 9. The element will try to maintain this ratio as its size changes. Set width: 100% and the height adjusts automatically. For square elements: aspect-ratio: 1 / 1 (or just aspect-ratio: 1). You can also use decimal values: aspect-ratio: 1.7778. The auto keyword (aspect-ratio: auto) uses the element's intrinsic ratio — useful for images that should keep their natural proportions with auto as a fallback: aspect-ratio: auto 16 / 9.

/* CSS aspect-ratio property */

/* Basic usage */
.video { aspect-ratio: 16 / 9; width: 100%; }
.square { aspect-ratio: 1; width: 200px; }
.photo { aspect-ratio: 4 / 3; }

/* Responsive video embed */
.video-wrapper {
  aspect-ratio: 16 / 9;
  width: 100%;
  max-width: 800px;
}
.video-wrapper iframe {
  width: 100%;
  height: 100%;
}

/* Card with fixed ratio */
.card-image {
  aspect-ratio: 3 / 2;
  object-fit: cover;
  width: 100%;
}

/* Browser support: 95%+ (Chrome 88+, Firefox 89+, Safari 15+) */
/* Fallback: padding-top hack */
.fallback { padding-top: 56.25%; /* 9/16 = 0.5625 */ }

Common patterns

Responsive video container: .video-container { aspect-ratio: 16 / 9; width: 100%; } with the iframe or video filling it via position: absolute and inset: 0. Image card grid: set aspect-ratio: 3 / 2 on the img element with object-fit: cover to create uniform image grids. Hero section: aspect-ratio: 21 / 9 for a cinematic banner that scales with viewport width. Avatar circle: aspect-ratio: 1 with border-radius: 50%.

Browser support and fallbacks

aspect-ratio is supported in Chrome 88+, Firefox 89+, Safari 15+, and Edge 88+ (since early 2021). For older browsers, use the padding-top fallback: .container { position: relative; padding-top: 56.25%; } .container > * { position: absolute; inset: 0; }. The 56.25% comes from 9/16 × 100. Use @supports (aspect-ratio: 1) { ... } to progressively enhance. For images, setting width and height HTML attributes gives the browser the intrinsic ratio for layout calculation even before CSS loads.

Frequently Asked Questions

Can I use aspect-ratio on images?

Yes. Setting aspect-ratio on an img element reserves the correct space in the layout before the image loads, preventing Cumulative Layout Shift (CLS). Combine with object-fit: cover or contain to control how the image fills the box. Setting width and height HTML attributes achieves the same layout reservation.

What is the padding-top aspect ratio hack?

Before the aspect-ratio CSS property existed, developers used padding-top as a percentage of the width to create ratio-locked containers. For 16:9: padding-top: 56.25% (9 ÷ 16 × 100). Content inside uses position: absolute. This hack is no longer needed in modern browsers but still works as a fallback.

Does aspect-ratio work with flexbox and grid?

Yes. The aspect-ratio property works in flex items and grid items. In flex layouts, set flex-shrink: 0 if you want the item to maintain its ratio without being squished. In grid, use min-height: 0 on the item to allow the ratio to take effect when the grid cell has an implicit size.

Related Inspect Tools