Skip to content
SevenOne

Search documentation

Search pages and components

Aspect Ratio

Keeps images, videos and maps at a fixed ratio, such as 16/9, at any width.

Installation

npx shadcn@latest add @sevenone/aspect-ratio

Usage

import { AspectRatio } from "@/components/ui/aspect-ratio"

Examples

16/9

<AspectRatio ratio={16 / 9} className="rounded-lg bg-muted">
  <img src="/photo.jpg" alt="Describe the photo" className="size-full rounded-lg object-cover" />
</AspectRatio>

Square and portrait

1/1
3/4
<AspectRatio ratio={1}>…</AspectRatio>
<AspectRatio ratio={3 / 4}>…</AspectRatio>

Accessibility

  • Give every image inside it a useful alt text, or an empty alt when it is only decoration.
  • Videos need captions and controls; the ratio only sets the shape.