Aspect Ratio
A box that keeps its width-to-height ratio at any width. It is shadcn's AspectRatio, unchanged, and draws nothing itself: round the media with Nelumbo's radius.
Install
npx shadcn@latest add @nelumbo/aspect-ratioRatios
Pass ratio as width over height. Photos and video use 16 / 9, square thumbnails 1, portraits 3 / 4.
Nelumbo radius
rounded-xl suits photos and cards, rounded-2xl large hero images, rounded-full an avatar-like crop. Add overflow-hidden when the box holds an image.
Usage
<AspectRatio ratio={16 / 9} className="overflow-hidden rounded-xl bg-surface-container-high"> <img src="/cover.jpg" alt="" className="size-full object-cover" /></AspectRatio>Props
| Prop | Type | Default | Notes |
|---|---|---|---|
ratio | number | 1 | Width divided by height. |
asChild | boolean | false | Render the child element as the box. |