Aspect Ratio
Holds children at a fixed shape, from 16 / 9 or "4:3". Optional hairline frame with a lit corner tick.
New in 1.7.
9:41 / 24:18
Installation
npx shadcn@latest add https://neonkit.heyaadi.com/r/aspect-ratio.jsonUsage
import { AspectRatio } from "@/components/ui/aspect-ratio"
<AspectRatio ratio={16 / 9}>
<img src="/talk.jpg" alt="Main stage" className="h-full w-full object-cover" />
</AspectRatio>Examples
Common shapes
ratio takes a number or a string: 1, 16 / 9, "4:5" or "9/16".
Lit corner as selection
The tick marks the picked tile. Inside each, a second AspectRatio letterboxes the screenshot at its real shape; portrait ones are sized by height with h-full w-auto.
API reference
Renders a div and accepts its attributes; the ref points at it. Children fill an inner box clipped to the corners.
| Prop | Type | Default |
|---|---|---|
ratio | numberWidth over height. Strings like "16:9" or "21/9" work too. Anything invalid falls back to 1. | 1 |
frame | booleanAdds a 12px radius, a white/10 hairline and a lit tick on one corner. true puts it top left. | false |
color | NeonColorColor of the tick. Falls back to --neon-accent, then cyan. | inherited |
Accessibility
- It uses the CSS aspect-ratio property. Set a width (it fills its parent by default) or, for a box sized by height, h-full w-auto.
- Children are positioned inside an absolute box, so media should be h-full w-full with object-cover or object-contain.
- The frame is decoration and is hidden from assistive tech. Give images their own alt text.