Foundations · stable · MIT

Aspect Ratio

A predictable media frame that preserves a numeric ratio.

Install editable source

Add Aspect Ratio

Base UI / canonicalnpx shadcn@latest add https://gummyui.dev/r/gummy-aspect-ratio.json

No package dependency beyond React. Shared Gummy material is resolved automatically.

Behavior contract

Semantics before surface

Semantics

A styled div with intrinsic aspect-ratio behavior.

Keyboard

No component-specific keys.

System support

Light and dark themes, logical RTL layout, reduced motion, responsive content, and forwarded public refs.

Source-derived reference

Anatomy and public API

Exported anatomy

These public React parts are read directly from the canonical source during the documentation build.

  • GummyAspectRatio

Prop contracts

GummyAspectRatioProps

Composes React.HTMLAttributes<HTMLDivElement> & { ratio?: number; fit?: "cover" | "contain" | "fill"; }

Troubleshooting

Check behavior before surface.

Implementation decisions

When to use Aspect Ratio

Use a fixed aspect ratio when media needs predictable geometry before it loads or while it changes across sources. Supply meaningful alternative text when the image carries information, and an empty alternative when it is decorative. Choose object-fit behavior deliberately so important content is not cropped. Test unusually tall, wide, missing, and slow media, plus zoom and small containers, before treating the reserved frame as complete.

Live product source

Inspect the canonical states

The Component Lab exercises real source across default, focus, disabled, responsive, dark, reduced-motion, and RTL contexts.

Open the live Component Lab

Interactive inspection

Try Aspect Ratio in context

Load the real component preview when you are ready to interact with its responsive, theme, and direction controls.

Editable source

Read before you install

Canonical Base UI or native source

The registry payload stays off the initial page request.