aspect‑ratio with min/max Demo - Online Responsive Boxes
Combine aspect‑ratio with min‑/max‑width/height and see how the box responds. Understand sizing constraints. Copy the pattern.
UD5 Toolkit
Choose a preset or set custom dimensions
See how your aspect ratio box renders in a container
aspect-ratio is supported in all modern browsers (Chrome 88+, Firefox 89+, Safari 15+). Use the Padding Hack tab for legacy browser support.
The aspect-ratio CSS property defines the width-to-height ratio of an element's box. It tells the browser to calculate the element's height based on its width (or vice versa), maintaining a consistent proportion. For example, aspect-ratio: 16 / 9 ensures the element stays at a 16:9 widescreen ratio regardless of container size.
The modern aspect-ratio property is a native CSS solution—cleaner, more readable, and doesn't require extra wrapper elements or absolute positioning. The older padding-top hack relies on the fact that vertical padding percentages are calculated based on the element's width, creating a fixed ratio box. While both achieve similar results, aspect-ratio is far simpler and works seamlessly with flexbox and grid layouts.
The padding-top hack uses the CSS rule that percentage-based padding is always relative to the element's width. By setting padding-top: 56.25% (for 16:9, since 9÷16×100=56.25) on a relatively positioned container and absolutely positioning the content inside, you create a box that maintains its aspect ratio. This technique was widely used before native aspect-ratio support became available.
aspect-ratio is supported in Chrome 88+, Firefox 89+, Safari 15+, and Edge 88+—covering approximately 96%+ of global web traffic as of 2024. For legacy browser support (mainly older Safari versions and IE), the padding-top hack remains a reliable fallback.
Absolutely! aspect-ratio works excellently with <img> and <video> elements. Combined with object-fit: cover or object-fit: contain, you can create responsive media containers that maintain perfect proportions while the content fills the available space. This is particularly useful for video embeds, thumbnail galleries, and hero images.
If the content inside an aspect-ratio box is larger than the box itself, it will overflow by default. To handle this gracefully, add overflow: hidden to clip excess content, or use overflow: auto to add scrollbars. For images and videos, object-fit: cover is often the best solution—it scales the media to cover the box while maintaining its own aspect ratio.
Common ratios serve different purposes: 16:9 is standard for video and hero sections; 4:3 suits traditional photography; 1:1 works for profile images and social media thumbnails; 3:2 is classic for photo prints; 21:9 creates cinematic ultra-wide effects; 9:16 is ideal for mobile-first vertical content like Stories and Reels. Choose based on your content type and layout needs.
Yes—and this is one of its biggest advantages over the padding-top hack. aspect-ratio integrates seamlessly with modern layout systems. In flexbox, a flex child with aspect-ratio will maintain its proportions while flexing. In CSS Grid, you can combine aspect-ratio with 1fr tracks to create beautifully proportional responsive layouts without complex calculations.
Combine aspect‑ratio with min‑/max‑width/height and see how the box responds. Understand sizing constraints. Copy the pattern.
Upload a small pixel art image and get a CSS grid layout that recreates it using divs. Novelty developer tool.
Resize and crop an image to a specific aspect ratio (1:1, 16:9…) with automatic fit/cover. Download the perfect image.
Drag a virtual ruler across your screen to measure pixel distances. Horizontal and vertical guides. Useful for UI designers checking alignment.
Visually name grid areas in a table and generate grid‑template‑areas CSS. Perfect for complex layouts. Drag‑free.
Upload an image at multiple widths and generate a complete <picture> or <img srcset> snippet. Modern web performance.
Detect your current screen resolution, viewport dimensions, and device pixel ratio. Useful for responsive design testing. No data collection.
Wrap text around an irregular shape and adjust the margin and alpha threshold. Magazines layout on the web.
Paste image URLs and generate a responsive masonry or justified gallery layout with lightbox. Copy the HTML/CSS/JS.
Paste media queries and see a visual indicator of which rules apply at current viewport size.
Upload one image at multiple widths and generate the complete img srcset and sizes attributes. Perfect for performance.
Predict the file size of an image based on pixel dimensions and format (JPEG, PNG, WebP). Rough estimate. Local.
Build a CSS media query by selecting feature, operator, and value. Copy the exact syntax for your stylesheet.
An on‑screen ruler that measures in pixels, centimeters, and inches. Drag to resize. Handy for UI designers and developers.
Upload multiple sizes of the same image and generate the complete srcset and sizes attributes. For perfect responsive performance.
Experiment with CSS container queries in a live editor. Resize the container and see styles change based on its width/height. Learn modern responsive.
Toggle image‑rendering: auto, pixelated, crisp‑edges on a scaled image. Essential for pixel art display.
Browse the OKLCH color space with sliders for lightness, chroma, and hue. See the CSS oklch() code. Modern and accessible.
See the current viewport width/height, document size, scrollbar width, and pixel ratio. Essential responsive data.
Experiment with the CSS color-mix() function. Pick two colors and mix them in different color spaces (srgb, oklch). Copy the CSS.
Test the new style() function inside @container to query custom property values. Revolutionary component‑based responsive design.
Resize a video by cropping to a new aspect ratio or scaling up/down. Apply and download the result. Browser‑based.
Interactively apply CSS filter functions (blur, brightness, contrast, etc.) to an image and copy the resulting filter property. No coding required.
Add a decorative rectangular border/frame to your image. Adjust width, color, and shadow. Download the framed photo.
Resize an image to exact dimensions and add colored padding to fill the aspect ratio without cropping. Useful for profile grids.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Write a media query and see if it matches as you resize the iframe. Understand width, height, and resolution queries.
Display your screen's current devicePixelRatio. See how it changes when you zoom. Useful for high‑res image decisions.
Enlarge pixel art or low‑res images without blur. Choose 2x, 4x, 8x. Perfect for sprites. Download scaled PNG.
Crop images into rectangular or circular shapes with interactive handles. Output as PNG or JPEG. A simple, browser-based tool with no uploads required.