What Is the CSS Aspect Ratio Calculator?
Calculate and generate CSS aspect-ratio property values. Preview how different ratios (16:9, 4:3, 1:1, 21:9) affect element dimensions.
Why Use This Tool?
The CSS aspect-ratio property replaces the old padding-top percentage hack for maintaining element proportions. This tool helps you find the right ratio and generates the CSS.
How to Use This CSS Aspect Ratio
- Enter your desired ratio — Type the aspect ratio you need — common values include 16/9 (widescreen), 4/3 (traditional), 1/1 (square), and 21/9 (ultrawide).
- Set the element width — Define the width of your element in any CSS unit (px, %, vw). The height will be calculated automatically based on the ratio.
- Preview the result — See your aspect-ratio box rendered live with the correct proportions applied.
- Copy the CSS — Grab the modern
aspect-ratioproperty or the legacy padding-bottom hack for older browser support.
Tips and Best Practices
- → Use the native
aspect-ratioproperty. Modern CSS supportsaspect-ratio: 16 / 9directly — no padding tricks needed. It's supported in all modern browsers since 2021. - → The padding-bottom trick is legacy. Before
aspect-ratio, developers usedpadding-bottom: 56.25%for 16:9 ratios. Only use this if you need to support very old browsers. - → Prevent layout shift with aspect-ratio. Setting aspect-ratio on images and video containers reserves the correct space before content loads, eliminating Cumulative Layout Shift (CLS) — a key Core Web Vital.
- → Combine with object-fit. Use
object-fit: coverwith aspect-ratio on images to maintain proportions without distortion while filling the container.
Frequently Asked Questions
Built by Derek Giordano · Part of Ultimate Design Tools