Aspect Ratio
LayoutKeeps a media container at a chosen width-to-height ratio as its available width changes.
Try it
Add to your project
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/aspect-ratio.jsonThe command includes the component’s shared dependencies. Your project keeps editable source files.
Include the complete example
This example also composes shape, typography. Install its parts together:
npx shadcn@latest add https://luv-jeri.github.io/cojeev-ui/r/aspect-ratio.json https://luv-jeri.github.io/cojeev-ui/r/shape.json https://luv-jeri.github.io/cojeev-ui/r/typography.jsonUsing aspect ratio
Set ratio for images, video, or previews that should retain a predictable shape.
Control the child media sizing and object-fit to decide whether it crops or leaves space.
API
Compose the exported parts below. The prop types are read from the React source during the registry build.
Native element or underlying primitive props are inherited where declared, including accessible labels, event handlers and refs.
AspectRatioProps
| Prop | Type | Required |
|---|---|---|
variant | "default" | "pink" | "yellow" | "blue" | "olive" | null | undefined | No |
size | "default" | null | undefined | No |
ratio | number | No |
Accessibility
Provide appropriate alternative text, captions, and controls on the media itself; the ratio wrapper adds no content description.
States and appearance
For conditional content, keep a MotionPresence boundary around keyed MotionSurface children. The shared entrance and exit states work with native primitives and respect your motion preference.
Try pointer and keyboard interaction, and switch the appearance control in the navigation to compare light and dark mode. Motion respects reduced motion preferences.