Presets

Blocks

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.

Upgrade
JoinLogin
Presets
Monochrome
Overview
  • Introduction
  • Components
  • Installation
Components
  • Accordion
  • Alert
  • Alert Dialog
  • Aspect Ratio
  • Avatar
  • Badge
  • Breadcrumb
  • Button
  • Button Group
  • CalendarNEW
  • Card
  • CarouselNEW
  • Checkbox
  • Collapsible
  • Dialog
  • Dropdown Menu
  • Empty
  • Field
  • Input
  • Input Group
  • Item
  • Kbd
  • Label
  • Native Select
  • Scroll Area
  • SelectNEW
  • Separator
  • SwitchNEW
  • Table
  • Tabs
  • Textarea
  • TooltipNEW

Aspect Ratio

PreviousNext

Displays content within a desired ratio.

1import { AspectRatio } from "@/components/ui/aspect-ratio";23export default function Preview() {4  return (

Installation

pnpm dlx sprawlify@latest add aspect-ratio
npx sprawlify@latest add aspect-ratio
yarn sprawlify@latest add aspect-ratio
bunx --bun sprawlify@latest add aspect-ratio

Install the following dependencies:

pnpm add @sprawlify/primitives @sprawlify/react
npm install @sprawlify/primitives @sprawlify/react
yarn add @sprawlify/primitives @sprawlify/react
bun add @sprawlify/primitives @sprawlify/react

Add the following files to your project:

aspect-ratio.tsx
1"use client";23import { AspectRatio as AspectRatioPrimitive } from "@sprawlify/react/aspect-ratio";45function AspectRatio({6  children,7  ...props8}: React.ComponentProps<typeof AspectRatioPrimitive.Root>) {9  return (10    <AspectRatioPrimitive.Root data-slot="aspect-ratio" {...props}>11      <AspectRatioPrimitive.Content data-slot="aspect-ratio-content">12        {children}13      </AspectRatioPrimitive.Content>14    </AspectRatioPrimitive.Root>15  );16}1718export { AspectRatio };19

Update the import paths to match your project setup.

Usage

1import { AspectRatio } from "@/components/ui/aspect-ratio"
1<AspectRatio ratio={16 / 9} className="bg-muted">
2  <img src="..." className="size-full rounded-md object-cover" />
3</AspectRatio>

Examples

Portrait

A portrait aspect ratio component using the ratio={9 / 16} prop. This is useful for displaying images in a portrait format.

1import { AspectRatio } from "@/components/ui/aspect-ratio";23export default function Preview() {4  return (

Square

A square aspect ratio component using the ratio={1 / 1} prop. This is useful for displaying images in a square format.

1import { AspectRatio } from "@/components/ui/aspect-ratio";23export default function Preview() {4  return (

On This Page

InstallationUsageExamplesPortraitSquare

Get PRO

Need premium blocks and templates? Upgrade to PRO and get access.