CSS Aspect Ratio Calculator
Calculate and generate CSS aspect-ratio property values with live preview. Enter custom dimensions, use preset ratios, simplify with GCD, and copy production-ready CSS. Everything runs in your browser.
How to Use the CSS aspect-ratio Property
The CSS aspect-ratio property sets a preferred aspect ratio for an element's box, which the browser uses to calculate auto-sized dimensions. It was introduced as a modern replacement for the padding-top percentage hack that developers previously used to create responsive containers with fixed proportions.
Basic Syntax
The property accepts a ratio value written as width / height. For example, aspect-ratio: 16 / 9 creates a widescreen container. If you set the width, the browser calculates the height automatically (and vice versa). You can also use a single number: aspect-ratio: 1.778 is equivalent to 16 / 9.
Common Use Cases
- Video embeds:
aspect-ratio: 16 / 9for responsive YouTube or Vimeo containers - Image placeholders: Prevent layout shift by reserving space before images load
- Card layouts: Ensure consistent card proportions in a grid
- Hero sections: Create viewport-proportional hero areas
- Social media embeds: Match platform-specific aspect ratios (1:1, 4:5, 9:16)
GCD Simplification
This tool automatically simplifies ratios using the Greatest Common Divisor (GCD) algorithm. For instance, entering 1920 x 1080 simplifies to 16:9, and 2560 x 1440 simplifies to 16:9 as well. This makes the CSS cleaner and more readable while producing the exact same visual result.
Browser Support
The aspect-ratio property is supported in all modern browsers: Chrome 88+, Firefox 89+, Safari 15+, and Edge 88+. This gives it over 95% global browser coverage. For older browsers, you can use the @supports rule to provide a padding-top fallback.
Features
- 8 preset aspect ratios: 1:1, 4:3, 3:2, 16:9, 21:9, 2:3, 9:16, golden ratio
- Custom width/height input with live preview
- Automatic GCD simplification (e.g. 1920x1080 to 16:9)
- 8 common resolution quick-apply buttons
- Dimension calculator: enter width to get height, or height to get width
- Visual preview box that updates in real time
- Syntax-highlighted CSS output with one-click copy
- Keyboard shortcuts: Ctrl+Shift+C to copy, Ctrl+L to reset
- 100% client-side — nothing is sent to any server