AspectRatio

Media

Container enforcing aspect ratio constraints with responsive behavior and overflow handling

Preset Aspect Ratios

Square (1:1)

Loading...
1:1

Standard (4:3)

Loading...
4:3

Widescreen (16:9)

Loading...
16:9

Ultrawide (21:9)

Loading...
21:9

Photo (3:2)

Loading...
3:2

Portrait (9:16)

Loading...
9:16

Visual Variants (16:9)

Default

Loading...
Mountain landscape

Bordered

Loading...
Forest path

Glass

Loading...
Sunset

Glass Strong

Loading...
Lake

Gradient

Loading...
Valley

Overlay Gradients

Bottom Overlay

Loading...
Mountain peak

Mountain Vista

Breathtaking views

Top Overlay

Loading...
Snow mountain

Alpine Heights

Snow-capped peaks

Custom Ratios

Use numeric or string-based custom ratios.

Custom 2.5:1 Ratio

Loading...
Custom 2.5:1

Custom 1.5:1 Ratio

Loading...
Custom 1.5:1

Custom "1.3:2.3"

Loading...
1.3:2.3

Custom "5:7"

Loading...
5:7

Custom "2.5:1"

Loading...
2.5:1

Custom Numeric 2.5

Loading...
2.5

Interactive Examples

Zoom on Hover

Default Zoom (1.1x)

Loading...
Mountain

Strong Zoom (1.5x)

Loading...
Nature

Subtle Zoom (1.05x)

Loading...
Sunset

Callbacks (click & hover)

Click to Count

Loading...
Click Me!

Hover Detection

Loading...
Hover Me!

Click + Hover + Zoom

Loading...
Interactive!

Usage Guidelines

When to Use

  • Video embeds
  • Image containers
  • Responsive media

Accessibility

  • Maintains image accessibility
  • Alt text preserved

Performance

  • Pure CSS implementation
  • No JavaScript

Common Mistakes

  • Wrong aspect ratio for content
  • Not handling content overflow

Frequently Asked Questions

View on GitHub

See the full source code on GitHub