Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Context Menu
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Menubar
- Message
- Meter
- Number Field
- OTP Field
- Pagination
- Popover
- Preview Card
- Progress
- Questionnaire
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Shared
- Artifact
- Audio Player
- Canvas
- Chain of Thought
- Checkpoint
- Code Block
- Commit
- Connection
- Context
- Controls
- Edge
- Environment Variables
- Mic Selector
- Model Selector
- Node
- Node Toolbar
- Open in Chat
- Panel
- Plan
- Prompt Input
- Queue
- Reasoning
- Sandbox
- Schema Display
- Shimmer
- Snippet
- Sources
- Speech Input
- Stack Trace
- Suggestion
- Tool
- Transcription
- Web Preview
Hooks
Resources
Aspect Ratio
Constrains its content to a fixed width-to-height ratio.
16 / 9
import { AspectRatio } from "@/components/ui/aspect-ratio";
export default function Particle() {
return (
<AspectRatio className="w-full overflow-hidden rounded-md border" ratio={16 / 9}>
<div className="flex size-full items-center justify-center bg-muted text-muted-foreground text-sm">
16 / 9
</div>
</AspectRatio>
);
}
Installation
pnpm dlx shadcn@latest add @frontal-labs/aspect-ratio
Usage
import { AspectRatio } from "@/components/ui/aspect-ratio";<AspectRatio ratio={16 / 9}>
<img alt="" className="size-full object-cover" src="/photo.jpg" />
</AspectRatio>API Reference
AspectRatio
A div that applies the given ratio through the CSS aspect-ratio property.
| Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | — | Width divided by height, for example 16 / 9. Required. |
All other div props are forwarded.
Examples
Common Ratios
1 / 1
4 / 3
21 / 9
import { AspectRatio } from "@/components/ui/aspect-ratio";
const ratios = [
{ label: "1 / 1", value: 1 },
{ label: "4 / 3", value: 4 / 3 },
{ label: "21 / 9", value: 21 / 9 },
];
export default function Particle() {
return (
<div className="grid w-full gap-4 sm:grid-cols-3">
{ratios.map((ratio) => (
<AspectRatio
className="overflow-hidden rounded-md border"
key={ratio.label}
ratio={ratio.value}
>
<div className="flex size-full items-center justify-center bg-muted text-muted-foreground text-sm">
{ratio.label}
</div>
</AspectRatio>
))}
</div>
);
}
Constraining an Image
import { AspectRatio } from "@/components/ui/aspect-ratio";
export default function Particle() {
return (
<AspectRatio className="w-full overflow-hidden rounded-md border" ratio={16 / 9}>
<img
alt="Layered rock formations"
className="size-full object-cover"
height={450}
src="https://images.unsplash.com/photo-1588345921523-c2dcdb7f1dcd?w=800&dpr=2&q=80"
width={800}
/>
</AspectRatio>
);
}