Components/Data display/Aspect Ratio
COMPONENT48.48

Aspect Ratio

Media box that holds a fixed ratio through the native CSS aspect-ratio property. The child image fills and crops.


INSTALL

1pnpm dlx @sayagodev/mo add aspect-ratio

Or import the files from the package (no copy):

1import "@sayagodev/mo/css/aspect-ratio.css";

EXAMPLES

Landscape 16/9
Photo by shadcn
Portrait 9/16
Photo by shadcn
Square 1/1
Photo by shadcn
Ultrawide 21/9
Ultrawide photo
Video 16/9
RTL
صورة جميلة
منظر طبيعي جميل

USAGE

1<div data-aspect-ratio="16/9">2  <img src="…" alt="Photo" />3</div>

API

NAMEKINDDESCRIPTION
[data-aspect-ratio]attributeDefaults to 16/9; named values 1/1 · 4/3 · 9/16 · 21/9
[data-slot="aspect-ratio"]attributeShadcn alias — same styles as [data-aspect-ratio]
> :is(img, video, iframe)elementFills 100% and crops with object-fit: cover via shared.css
--mo-aspect-ratio / --ratiotokenAny custom ratio, e.g. 3/2 — --ratio is the shadcn-compatible alias

FILES

src/css/aspect-ratio.css
Install:mo add aspect-ratio

THEMING · PLAYGROUND

This is the exact component from the examples above, wearing a completely different theme. Edit the tokens and --mo-* hooks in the editor — autocomplete knows them all — and the preview obeys in real time. Your CSS always wins.

Tokens & hooks — edit live
Global tokens
--muted
Component hooks
--mo-aspect-ratio

Preview

Placa Nuo

Your CSS

Try it: type --mo- for the component hooks, or edit any value — the preview obeys in real time.