CSS aspect-ratio Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout & Media

What You’ll Learn

The aspect-ratio property lets you lock an element’s width-to-height proportion. It is especially useful for videos, images, cards, and embeds that should stay visually consistent on every screen size.

01

Proportions

Keep width and height balanced.

02

Syntax

Use ratios like 16 / 9.

03

Responsive Media

Great for video and images.

04

auto Default

Natural sizing when unset.

05

object-fit

Pair with cover for photos.

06

Layout Stability

Reduce content jumping.

Definition and Usage

The aspect-ratio CSS property defines a preferred width-to-height ratio for a box. When you set only the width (or only the height), the browser can calculate the missing dimension so the element keeps that shape.

This is particularly helpful for media layouts. A video wrapper can stay widescreen at 16 / 9, a profile photo can stay square at 1 / 1, and a gallery tile can stay at 4 / 3 even when the page reflows on mobile.

💡
Beginner Tip

Think of aspect-ratio as a rule that says “always keep this shape.” Set the width to 100%, add aspect-ratio: 16 / 9;, and the height adjusts automatically.

📝 Syntax

Write aspect-ratio with a ratio value or the keyword auto:

syntax.css
selector {
  aspect-ratio: <ratio> | auto;
}

Basic Example

aspect-ratio.css
.video-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #e2e8f0;
}

Syntax Rules

  • Use a width/height ratio such as 16 / 9, 4 / 3, or 1 / 1.
  • You can also use a decimal number such as 1.5, which equals a 3 / 2 ratio.
  • Spaces around the slash are optional, but 16 / 9 is easier to read for beginners.
  • The keyword auto restores natural sizing based on content or other properties.
  • aspect-ratio works best when combined with a defined width or max-width.

⚡ Quick Reference

QuestionAnswer
Initial valueauto
Applies toAll elements
InheritedNo
AnimatableNo
Common useResponsive videos, images, cards, and embeds

Default Value

The initial value of aspect-ratio is auto. That means the browser uses the element’s natural content dimensions or explicit width and height values unless you set a ratio yourself.

💎 Property Values

These are the value types you will use most often with aspect-ratio.

ValueExampleMeaning
Width / height ratioaspect-ratio: 16 / 9;Widescreen layout, common for video players
Square ratioaspect-ratio: 1 / 1;Equal width and height, useful for avatars
Photo ratioaspect-ratio: 4 / 3;Classic camera and gallery proportions
Decimal ratioaspect-ratio: 1.5;Same as 3 / 2 in decimal form
autoaspect-ratio: auto;Uses natural or content-based sizing
16 / 9 4 / 3 3 / 2 1 / 1
16 / 9

The standard widescreen ratio used for videos, hero banners, and embedded players.

Resize the browser to see the box stay widescreen.

1 / 1

A perfect square for profile photos, icons, and social thumbnails.

Width and height always match.

4 / 3

A classic photo ratio that feels slightly taller than widescreen media.

Common for galleries and camera-style images.

3 / 2

A balanced landscape ratio often used for cards and blog previews.

Also writable as the decimal 1.5.

Common Use Cases

aspect-ratio is widely used anywhere layout stability and consistent proportions matter:

  • Video wrappers — Reserve space for <video> or embedded players before they load.
  • Responsive images — Pair with object-fit: cover so photos fill a frame without stretching.
  • Cards and thumbnails — Keep a grid of preview tiles visually aligned.
  • Iframes and embeds — Maintain predictable embed height on mobile and desktop.
  • Placeholder blocks — Prevent layout shift while content is loading.

aspect-ratio vs the Old Padding Hack

Before aspect-ratio, developers often used a percentage-based padding-top trick. The modern property is simpler and easier to read.

ApproachExampleNotes
Modern CSSaspect-ratio: 16 / 9;Clear, direct, and supported in current browsers
Legacy hackpadding-top: 56.25%;56.25% equals 9 ÷ 16 of the width; harder for beginners

👀 Live Preview

This box uses width: 100% and aspect-ratio: 16 / 9;. Try resizing the browser window:

The width follows the container, and the height adjusts automatically to preserve the widescreen ratio.

Examples Gallery

Try aspect-ratio with a video container, square avatar, responsive photo, and card grid.

📚 Media Layouts

Use aspect-ratio to reserve space for videos, images, and embeds before content finishes loading.

Example 1 — 16:9 Video Container

Set a widescreen ratio on a container so embedded video or iframe content always fits the expected shape.

video-container.html
<style>
  .video-container {
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: lightgray;
  }
</style>

<div class="video-container">
  <!-- Video or iframe goes here -->
</div>
Try It Yourself

How It Works

Only the width is set explicitly. The browser calculates the height from aspect-ratio: 16 / 9.

Example 2 — Square Avatar

Use 1 / 1 when you want a profile image or icon tile to stay perfectly square.

square-avatar.css
.avatar {
  width: 120px;
  aspect-ratio: 1 / 1;
  border-radius: 999px;
  background: #14b8a6;
}
Try It Yourself

How It Works

A width of 120px plus aspect-ratio: 1 / 1 forces the height to match, creating a square.

🎨 Responsive Media

Combine aspect-ratio with object-fit and grid layouts for polished responsive designs.

Example 3 — Photo Frame with object-fit

Give images a fixed frame ratio, then crop cleanly with object-fit: cover.

photo-frame.css
.photo-frame {
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.photo-frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
Try It Yourself

How It Works

The frame keeps a 4 / 3 shape, and the image fills it without distortion thanks to object-fit: cover.

Example 4 — Card Grid with Consistent Media

Apply the same ratio to every card image area so a responsive grid stays visually balanced.

card-grid.css
.card-media {
  aspect-ratio: 3 / 2;
  background: #6366f1;
}
Try It Yourself

How It Works

Each card media block shares the same 3 / 2 ratio, so the row looks even at any width.

🧠 How aspect-ratio Works

1

You choose a ratio

Pick a shape such as 16 / 9, 4 / 3, or 1 / 1.

Ratio value
2

You set one dimension

Usually width is set to 100% or a fixed size like 120px.

Width or height
3

The browser calculates the other side

The missing dimension is computed from the ratio so the box keeps the same shape.

Automatic sizing
=

Stable responsive layouts

Media and cards keep their proportions without manual height math.

Universal Browser Support

aspect-ratio is supported in all modern browsers. Older browsers ignore it, so provide sensible fallback sizing when needed.

Baseline · Modern browsers

Maintain proportions in today’s browsers

Chrome, Edge, Firefox, Safari, and Opera support aspect-ratio in current versions.

95% Modern browser support
Google Chrome88+ · Desktop & Mobile
Full support
Mozilla Firefox89+ · Desktop & Mobile
Full support
Apple Safari15+ · macOS & iOS
Full support
Microsoft Edge88+ · Chromium
Full support
Opera74+ · Modern versions
Full support

Fallback behavior

In unsupported browsers, set explicit height or use the older padding-top percentage technique.

💻
Internet Explorer No support · Use width/height or padding fallback
None
aspect-ratio property 95% supported

Bottom line: Use aspect-ratio confidently in modern responsive layouts. Pair it with explicit dimensions as a fallback when supporting very old browsers.

Conclusion

The aspect-ratio property is a valuable addition to modern CSS. It gives you a simple, readable way to maintain consistent proportions for videos, images, cards, and other layout elements.

Whether you need a widescreen player at 16 / 9, a square avatar at 1 / 1, or a gallery tile at 4 / 3, this property helps your designs look polished at any size.

💡 Best Practices

✅ Do

  • Set a width or max-width before relying on aspect-ratio
  • Use common ratios like 16 / 9, 4 / 3, and 1 / 1
  • Pair images with object-fit: cover when cropping is acceptable
  • Reserve space early to reduce layout shift while media loads
  • Test card grids and embeds on mobile and desktop widths

❌ Don’t

  • Expect ratio to work well without any defined width or height context
  • Stretch photos when object-fit would solve cropping cleanly
  • Mix conflicting fixed height values that fight the chosen ratio
  • Forget fallbacks for very old browsers if your audience still uses them
  • Use odd decimal ratios when a readable fraction is clearer

Key Takeaways

Knowledge Unlocked

Five things to remember about aspect-ratio

Use these points when building responsive media layouts.

5
Core concepts
📝02

Ratio Syntax

Use 16 / 9 or decimals.

Values
🎥03

Media Ready

Great for video and images.

Use case
04

auto Default

Natural sizing when unset.

Default
📈05

Less Jumping

Improves layout stability.

Benefit

❓ Frequently Asked Questions

The aspect-ratio property sets a preferred width-to-height ratio for an element. When only one dimension is defined, the browser calculates the other dimension to keep that ratio.
The initial value is auto, which means the element uses its natural content size or other sizing properties such as width and height.
Yes. You can use a ratio like 16 / 9 or a decimal like 1.777. Both describe the same widescreen proportion.
Yes. It is commonly used on img, video, iframe, and container elements to reserve space and prevent layout shift while media loads.
Width and height set fixed dimensions. aspect-ratio keeps proportions flexible so one size can scale while the other adjusts automatically.

Practice in the Live Editor

Open the HTML editor, set aspect-ratio, and resize the preview to see proportions stay consistent.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful