Skip to content
FiftyCalc Free calculators for all 50 states

CSS Aspect Ratio Calculator

Test cases replayed : 2 of 2 match · Methodology · No outside source listed

Enter the original width and height in pixels, and the width the element will be shown at.

Result

Sample figures

padding-top—%

aspect-ratio: width part —

  • aspect-ratio: height part—
  • Height at the displayed width (px)—

Estimate for planning only, not tax, legal, financial or medical advice. This calculator uses the method explained on this page.

CSS Aspect Ratio Calculator

Original width, in px: enter 1 or more. Prefilled example: 1,920.

Original height, in px: enter 1 or more. Prefilled example: 1,080.

Displayed width, in px: enter 0 or more. Prefilled example: 640.

How to use this calculator

Fill in the fields in this order; each step takes you to its field.

  1. Original width, in px: enter 1 or more.
  2. Original height, in px: enter 1 or more.
  3. Displayed width, in px: enter 0 or more.
  4. Read the result: padding-top; the panel also shows aspect-ratio: width part, aspect-ratio: height part and Height at the displayed width (px).

How this calculator works

The CSS aspect-ratio property (W3C CSS Box Sizing Module Level 4) takes width / height, which this calculator reduces by the greatest common divisor, e.g. 1920 × 1080 → 16 / 9.

For the older padding technique, vertical padding in percent is resolved against the element's width (CSS 2.1, box model), so padding-top = height ÷ width × 100% keeps the ratio. Height at a given width = width × h ÷ w.

The formula

  1. Pad=hw×100
Symbols used in the formula
SymbolMeaningUnit
wOriginal widthpx
hOriginal heightpx
Padpadding-top%

Worked example

Original width1,920 px
Original height1,080 px
Displayed width640 px
aspect-ratio: width part16
aspect-ratio: height part9
Height at the displayed width (px)360
  1. Pad=1,0801,920×100=56.25

padding-top 56.25 %

Each step uses the unrounded value of the step before it; figures on this page are rounded for display.

Frequently asked questions

What padding-top keeps a 16:9 ratio?

56.25%, because 9 ÷ 16 = 0.5625.

Is the padding hack still needed?

Current browsers support the aspect-ratio property, so aspect-ratio: 16 / 9 does the same job. The padding method still works for very old browsers.

What height does a 16:9 video need at 640 px wide?

360 px.

Related calculators