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.
Paste image URLs and generate a responsive masonry or justified gallery layout with lightbox. Copy the HTML/CSS/JS.
Build a CSS media query by selecting feature, operator, and value. Copy the exact syntax for your stylesheet.
Resize and crop an image to a specific aspect ratio (1:1, 16:9…) with automatic fit/cover. Download the perfect image.
Upload an image at multiple widths and generate a complete <picture> or <img srcset> snippet. Modern web performance.
Upload multiple sizes of the same image and generate the complete srcset and sizes attributes. For perfect responsive performance.
Paste media queries and see a visual indicator of which rules apply at current viewport size.
Enter image pixel dimensions and compute maximum print size at various DPI. With aspect ratio presets (4x6, 5x7, 8x10) and cropping preview. Local tool.
Construct a CSS‑only carousel with scroll‑snap and scroll‑driven animations. Configurable gap, items, and progress indicator. Copy the HTML/CSS.
Interactively create colors in HWB space and get the CSS hwb() function. Simplifies tint/shade workflows. Live preview.
Toggle image‑rendering: auto, pixelated, crisp‑edges on a scaled image. Essential for pixel art display.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Predict the file size of an image based on pixel dimensions and format (JPEG, PNG, WebP). Rough estimate. Local.
Upload one image at multiple widths and generate the complete img srcset and sizes attributes. Perfect for performance.
Paste a media query and instantly check for syntax errors. See if it's correctly formed. Quick developer tool.
Resize a video by cropping to a new aspect ratio or scaling up/down. Apply and download the result. Browser‑based.
Reduce GIF file size by lowering color count and removing duplicate frames. See side‑by‑side preview. All local.
A horizontal photo gallery that scrolls with a smooth CSS animation using scroll‑timeline. Pure HTML/CSS. Copy the code.
Wrap text around an irregular shape and adjust the margin and alpha threshold. Magazines layout on the web.
Detect your current screen resolution, viewport dimensions, and device pixel ratio. Useful for responsive design testing. No data collection.
Apply a pixel sorting glitch effect to your photo. Sort pixels by brightness, hue, or saturation. Create abstract art. Canvas.
Enlarge pixel art or low‑res images without blur. Choose 2x, 4x, 8x. Perfect for sprites. Download scaled PNG.
See the current viewport width/height, document size, scrollbar width, and pixel ratio. Essential responsive data.
Upload an image and see a slider comparison of different JPEG quality levels. Find the optimal file size vs. quality trade‑off.
Convert short video clips to GIFs with adjustable resolution, frame rate, and dithering. Preview before download. All local.
Crop images into rectangular or circular shapes with interactive handles. Output as PNG or JPEG. A simple, browser-based tool with no uploads required.
Generate placeholder images with custom dimensions, background color, and text. Supports SVG and raster output. Perfect for wireframing and mockups.
Turn any photo into a mosaic of colored blocks or pixel art. Choose block size and palette. Download as PNG. Pure canvas.
See how your page title and description will look in Google SERP. Check pixel width and character count. Local tool.