Getting Started
Components66
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Form
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Trace
import { AspectRatio } from "@/components/ui/aspect-ratio"
export function AspectRatioDemo() {
return (
<AspectRatio
ratio={16 / 9}
className="w-full max-w-sm overflow-hidden rounded-xl bg-muted outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10"
>
<img
src="https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=900&auto=format&fit=crop&q=80"
alt="An office with plants and desks"
className="absolute inset-0 size-full object-cover"
/>
</AspectRatio>
)
}Installation#
pnpm dlx shadcn@latest add https://ui.ikramhasan.com/r/aspect-ratio.json
Usage#
import { AspectRatio } from "@/components/ui/aspect-ratio"<AspectRatio ratio={16 / 9} className="overflow-hidden rounded-xl">
<img
src="..."
alt="Image"
className="absolute inset-0 size-full object-cover"
/>
</AspectRatio>Examples#
Square#
import { AspectRatio } from "@/components/ui/aspect-ratio"
export function AspectRatioSquare() {
return (
<AspectRatio
ratio={1 / 1}
className="w-full max-w-48 overflow-hidden rounded-xl bg-muted outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10"
>
<img
src="https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=900&auto=format&fit=crop&q=80"
alt="An office with plants and desks"
className="absolute inset-0 size-full object-cover"
/>
</AspectRatio>
)
}Portrait#
import { AspectRatio } from "@/components/ui/aspect-ratio"
export function AspectRatioPortrait() {
return (
<AspectRatio
ratio={9 / 16}
className="w-full max-w-40 overflow-hidden rounded-xl bg-muted outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10"
>
<img
src="https://images.unsplash.com/photo-1497366754035-f200968a6e72?w=900&auto=format&fit=crop&q=80"
alt="An office with plants and desks"
className="absolute inset-0 size-full object-cover"
/>
</AspectRatio>
)
}API Reference#
AspectRatio#
| Prop | Type | Default |
|---|---|---|
ratio | number | — |
className | string | — |
The frame is plain: give it a radius and, for photos, the 1px inset outline the Item and Attachment image tiles use (outline-1 -outline-offset-1 outline-black/10 dark:outline-white/10).