Ballmac UI home

Aspect Ratio

A CSS-native ratio frame that reserves space for media and safely handles invalid ratio values.

Quarterly overview
A clearer view of your work
A story with room to breathe

Installation

$ pnpm dlx shadcn@latest add @ballmac/aspect-ratio

Usage

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

The full example is in the Code tab above.

Examples

States and variants

API reference

PropTypeDefault
ratio

Width divided by height. Defaults to 16:9.

number16 / 9

Also accepts the standard attributes of its root element.

Use with AI

A CSS-native ratio frame that reserves space for media and safely handles invalid ratio values. With the shadcn MCP server set up (guide), ask your agent:

Add the Ballmac UI Aspect Ratio (@ballmac/aspect-ratio) to this project with the shadcn MCP, then use it where it fits.

Use it for

  • Reserve image or video space before it loads
  • Keep cards aligned across a grid

Not for

  • Use fixed height when cropping is intentional

Registry JSON: https://ui.ballmac.com/r/aspect-ratio.json

Credits

Based on shadcn/ui Aspect Ratio, adapted by Ballmac. Free to use in personal and commercial projects.

npm
None
Registry
shadcn/utils