Home Tools Blog About

CSS Aspect Ratio

In short

Generate CSS aspect-ratio with padding-top fallback, object-fit options, 16+ presets, decimal input. Live preview. Free, client-side.

  • Runs in your browser
  • Nothing uploaded
  • Free, no sign-up

Generate aspect-ratio CSS - with optional padding-top fallback for legacy browsers wrapped in @supports. 16+ presets. object-fit selector. HTML usage examples for div / img / video / iframe.

16:9 · 1.778:1 · padding-top 56.2500%

CSS


      

HTML


      
🛡
100% PrivateNo server uploads, ever
InstantRuns in your browser
💧
No WatermarksClean output, always
🆓
Free ForeverNo accounts, no limits

How to Use CSS Aspect Ratio

CSS Aspect Ratio · free online tool · All Tools Verse
CSS Aspect Ratio. Free online tool that runs in your browser.
  1. Enter width and height numbers, or pick a preset from the grouped dropdown (Video / Photo / Social / Web).
  2. Click ↓ Simplify by GCD to reduce (e.g., 1920×1080 → 16:9).
  3. Set CSS selector (default .ratio-box) and target element (div / img / video / iframe).
  4. Pick output style. Modern only uses aspect-ratio property (works in Chrome 88+, Firefox 89+, Safari 15+ - covers ~96% of browsers in 2026). padding-top only uses the legacy hack (works everywhere including IE 11). Both wraps the padding-top fallback in @supports not (aspect-ratio: 1 / 1) for safe progressive enhancement.
  5. For media elements, pick object-fit. cover crops to fill; contain letterboxes to fit.
  6. Copy CSS, copy HTML pattern, or download as aspect-ratio-{w}x{h}.css.

Frequently Asked Questions

How do I make an embedded video or iframe responsive?

Give the iframe width: 100%; height: auto; aspect-ratio: 16 / 9; and remove the fixed width/height attributes from the embed code (or leave them, CSS wins). The element then scales with its container while keeping the video shape, no wrapper div needed. For older-browser support, wrap it in a container using the padding-top fallback this tool generates, with the iframe positioned absolutely inside.

aspect-ratio vs padding-top – which to use?

Modern aspect-ratio: simpler, no wrapper element needed, works in Chrome 88+ (Jan 2021), Firefox 89+ (Jun 2021), Safari 15+ (Sep 2021), Edge 88+. As of 2026, ~96% of browsers globally support it. padding-top hack: works everywhere including IE 11, but requires a relatively-positioned wrapper with an absolutely-positioned child. Both via @supports: best of both worlds – modern browsers use the clean property, old browsers fall back. Pick “Both” if you must support <1% legacy traffic.

How does the padding-top fallback work?

Set the wrapper’s padding-top to (height/width × 100)% – this percentage is calculated from the parent’s width, so it scales responsively. For 16:9: padding-top: 56.25% (because 9/16 = 0.5625). The child element is absolutely positioned to fill the wrapper’s actual content area (which is now the desired aspect-ratio size).

What does object-fit do?

Controls how media (img / video) fits inside a sized container. cover: scale to cover the entire container, cropping if needed (most common for hero images). contain: scale to fit entirely inside, letterboxing the empty space. fill: stretch to exactly fill (distorts aspect). scale-down: like contain but never upscales smaller images. Use cover for backgrounds, contain for product photos where the whole image must show.

What’s the @supports wrapper?

CSS feature query that applies rules only if the browser does NOT support a given property. @supports not (aspect-ratio: 1 / 1) means “apply the inner rules only on browsers that lack aspect-ratio support.” Modern browsers ignore this block; legacy browsers apply the padding-top fallback inside.

What aspect ratios are common?

Video: 16:9 (1080p, 4K, YouTube), 21:9 (cinema), 2.39:1 (true cinemascope). Photo: 3:2 (DSLR), 4:5 (Instagram portrait). Social: 1:1 (Instagram square), 9:16 (Stories, Reels, TikTok), 3:1 (Twitter/X header). Web: golden ratio 1.618:1 (design), 16:10 (old monitors).

Why simplify by GCD?

Source dimensions like 1920×1080 are equivalent to 16:9 once reduced by their greatest common divisor (120). The CSS aspect-ratio property accepts either form, but 16 / 9 is the conventional way to write it and the more familiar form for anyone reading the code.

What about decimal aspect ratios?

CSS accepts decimals: aspect-ratio: 1.618 (golden ratio). The tool accepts any positive number including decimals. The display shows both forms (e.g., “16:9 · 1.778:1”) for clarity.

Does aspect-ratio prevent layout shift?

Yes – that’s its main benefit for images. Set aspect-ratio on an img element matching its intrinsic ratio, and the browser reserves the right amount of space before the image loads. No more CLS (Cumulative Layout Shift) jumps in your Core Web Vitals. Browsers since 2022 even infer aspect-ratio automatically from img’s width and height attributes.

Is anything uploaded?

No. The CSS is generated entirely in your browser with JavaScript – nothing is sent to a server, logged, or stored, and the tool keeps working offline once the page has loaded.

Keep going

Related Tools

All Developer tools →

CSS Animation Generator

Generate CSS @keyframes animations - 16 presets, full duration/timing/delay/direction/fill controls, prefers-reduced-motion wrapper. Live preview.…

CSS Beautifier

Beautify or minify CSS with proper nested @media/@keyframes/@supports handling, comment preservation, calc()/var() awareness. Free,…

CSS Border Radius Generator

Visual CSS border-radius with elliptical mode, 6 unit types (px/%/em/rem/vw/vh), 8 shape presets, live…

CSS Clip Path Generator

Visual clip-path builder - polygon / circle / ellipse / inset / path, 20+…

CSS Columns Generator

Generate CSS multi-column layout with column-count or column-width, gap, rule, fill, span, break-inside. Live…

CSS Cursor Generator

Browse 34 CSS cursors organized by category, with custom URL cursor builder. Live hover…

CSS Filter Generator

Generate CSS filter with 10 functions including drop-shadow, backdrop-filter mode, 8 preset combinations. Live…

CSS Flexbox Generator

Visual flexbox builder with container + per-item controls (flex-grow/shrink/basis/order/align-self) and 6 layout presets. Free,…

CSS Glassmorphism Generator

Visual frosted-glass CSS builder. 9 controls including backdrop-saturate, 6 presets, 4 background scenes to…

CSS Gradient Generator

Visual gradient builder with 6 types (linear, radial, conic + 3 repeating). 8 presets,…

CSS Grid Generator

Visual CSS Grid builder with grid-template-areas, auto-fit + minmax responsive tracks, per-item spans. 6…

CSS Media Query Generator

Build @media queries: width, dark mode, reduced-motion, hover, pointer, orientation, print. Free, offline, client-side,…

Share

Embed this tool

Add this free tool to your website. Copy and paste the code: