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.
Enter a router's MAC address or serial and generate the common default WPA passphrase for major ISP brands. Educational purpose only.
Design a layout where nested grids share track sizes with their parent via subgrid. Copy the complete CSS.
Pick colors for the shadcn/ui design system and generate the complete CSS variable theme file. Copy into your project.
Paste your CSS and see warnings for properties that have limited browser support. Links to CanIUse. Modernize safely.
Format a list of Q&A pairs and export as a CSV ready for Anki import. Simple line‑based template. Local.
Style underlines, overlines, and strike-throughs with colors, wavy styles, and thickness. Modern CSS text‑decoration.
Generate a random medieval occupation with a short description. For NPCs or historical curiosity. Local list.
Generate a hardboiled film noir plot with a detective, a dame, and a McGuffin. Great for creative writing prompts.
Generate a grand, aristocratic title like 'Duke of Waffleshire'. Perfect for silly fun or RPG characters. Local.
Design a button or card that glows on hover. Adjust shadow color, spread, and transition. Copy the CSS. Rich UI.
Create a realistic letterpress (debossed) text effect using CSS text‑shadow and background. Adjust depth and light direction. Copy code.
Generate a realistic‑sounding dinosaur name and see a fun description. Perfect for kids and writers.
Generate a subtle noise/grain texture as a CSS background pattern. Adjust opacity and size. For that film look.
Generate random but realistic‑looking data arrays (users, products, orders) with typos and missing fields. For test robustness.
Create a customizable checkerboard or grid background using pure CSS gradients. Adjust cell size and colors. Copy the code.
Create a custom HTML/CSS progress bar with percentage, colors, and animation. Copy the code. Modern UI element.
Fill in a few details and get a polished resignation letter. No data stored. Instant copy or print.
Paste plain text and turn it into a nested outline using indent levels or Markdown headings. Great for planning.
Convert short text into a black‑and‑white Braille bump image ready for embossing. Educational and inclusive.
Generate a random, somewhat meaningful song lyric line. Write your own hit with AI‑free randomness. All local.
A replica of the famous Flexbox Froggy game: solve alignment puzzles by writing CSS. Progress saved locally. Fun frontend learning.
Generate a realistic‑sounding exoplanet designation (e.g., Kepler‑442b) and a sci‑fi planet description. For worldbuilding.
Create a realistic‑looking fake tweet with any name, handle, text, likes, and retweets. Just for laughs. All local canvas.
Generate magic squares of odd order (3x3, 5x5, …). See the sum constant and verify rows, columns, diagonals. Educational math toy.
One click to get a hilarious excuse for being late, missing homework, or not doing chores. Pure comedy.
Design a realistic-looking fake receipt with custom store name, items, and total. For jokes and gags. No real transaction.