InputTestHub

Aspect Ratio CSS Generator

Generates aspect-ratio CSS and the padding-top fallback for responsive media containers.

Colour & Design Nothing uploaded No sign-up Free, unlimited
Colour & Design tool
Fill in the fields and press Generate.
In short The `aspect-ratio` property does what it says — `aspect-ratio: 16 / 9` on a container keeps that shape at any width — and it is supported everywhere that matters now. The padding-top fallback is worth understanding anyway, because it explains something genuinely counter-intuitive about CSS. A percentage padding resolves against the containing block's WIDTH, even for `padding-top` and `padding-bottom`. That is the whole trick: `padding-top: 56.25%` is 9/16 of the element's own width, so a zero-height box with that padding is always exactly 16:9, and an absolutely positioned child fills it. Almost nobody guesses that percentage vertical padding uses width; it is one of the odder corners of the box model and it powered every responsive video embed for a decade. What this actually prevents is layout shift. Without a reserved aspect ratio, an image or an embed has zero height until it loads and then suddenly pushes everything below it down — which is the single biggest contributor to a poor Cumulative Layout Shift score. Setting `width` and `height` attributes on an `<img>` achieves the same thing for images, and modern browsers use them purely to compute the ratio.

How to use the Aspect Ratio CSS Generator

  1. Fill in the fields with your own details.
  2. The generated code updates live in the output panel.
  3. Copy the code and paste it into your page, file or CMS.

About the Aspect Ratio CSS Generator

The Aspect Ratio CSS Generator generates aspect-ratio CSS and the padding-top fallback for responsive media containers. It runs as plain JavaScript inside the page, which means there is no upload step, no queue and no size limit imposed by a server — the only limit is your own device.

What people use it for

  • Making an embedded video responsive.
  • Preventing layout shift on images.
  • Getting the fallback right for older browsers.

Frequently asked questions

Do I need an account to use the Aspect Ratio CSS Generator?
No charge and no sign-up. There is no free tier to run out of because there is no paid tier — inputtesthub.com is funded by advertising rather than by metering the tool.
Is what I paste into the Aspect Ratio CSS Generator stored?
No. The Aspect Ratio CSS Generator runs entirely in your browser using JavaScript. Your input never reaches inputtesthub.com or any third party — open your browser's Network tab while you use it and you will see no request go out.
What problem does the Aspect Ratio CSS Generator solve?
In practice it gets used for three things: making an embedded video responsive. Preventing layout shift on images. Getting the fallback right for older browsers. It is built for exactly those cases rather than being a general-purpose tool with this bolted on.
Is there an app version?
Yes. The page is responsive and the tool works in Chrome, Safari, Firefox, Edge and Samsung Internet on both Android and iOS. There is no app to install and nothing to sign into.

Related colour & design tools

All 33
01

CSS Gradient Generator

Builds linear, radial and conic CSS gradients with multiple stops, live preview and copyable…

02

Box Shadow Generator

Builds CSS box shadows with multiple layers, live preview and copyable output including inset…

03

Text Shadow Generator

Creates CSS text shadows including outline, emboss, neon and long-shadow effects.

04

Border Radius Generator

Builds CSS border-radius including per-corner and elliptical values, with a live preview.

06

Neumorphism CSS Generator

Generates soft-UI shadows where an element appears extruded from or pressed into the background.

07

Cubic Bezier Generator

Builds CSS easing curves with a draggable preview and a library of standard easings.

08

CSS Filter Generator

Builds CSS filter chains — blur, brightness, contrast, grayscale, hue-rotate, invert…

09

CSS Transform Generator

Builds CSS transforms — translate, rotate, scale, skew and 3D perspective — with a live preview.

10

Flexbox Generator

Builds flexbox layouts visually and outputs the CSS, with every alignment and wrapping option…