Skip to content

Aspect ratio

A media frame that keeps its ratio and shows a skeleton until the image loads.

ratio takes a number, "16/9" or "4:3". A direct child img, video, picture or iframe fills the frame; anything else is positioned by you.

Ratios

16/9
4:3
1

With an image

Tasks closed per week, rising over six weeks

Loading and failed

A cover that has not arrived yet
A cover that failed to load
A cover that failed to load, with its own fallback icon

Installation

npx shadcn@latest add @khaeli/aspect-ratio

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • @base-ui/react ^1.7.0
  • @keyline-icons/react ^2.2.0

Accessible name

  • The frame has no role. The image inside carries the name: give it an alt, or alt="" when it is decoration.
  • While the image loads the frame has aria-busy="true". The skeleton and the fallback icon are decoration, so a failed image is still announced by its alt.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/aspect-ratio.json