Aspect Ratio
Constrains slotted media or content to a fixed width:height ratio while filling the container's width. A slotted img or video fills the box and crops to cover automatically.
16:9 media
Installation
Copy the piece into your app — it compiles with your build and the code is yours:
puzzle add piece aspect-ratio
Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import AspectRatio from '@/components/ui/AspectRatio.pzl';
<div class="w-full max-w-lg"><AspectRatio ratio={ 16 / 9 } class="overflow-hidden rounded-xl border border-border"></AspectRatio></div>Common ratios
1:1
4:3
16:9
21:9
Wrapping any content
Centered content
Not just media — any slotted content fills the box.
The default ratio is 1 (a square). The root has no overflow rule — add overflow-hidden via class if you want content clipped to the box's corners.