elements
Blog Demos UI Docs Pricing
Elements Manual
  • Getting Started
  • CLI
  • Build
  • Browser
  • Packages
  • TypeScript
  • Elements HTML
  • Assets
  • RPC
  • Router
  • Session
  • Database
  • Migrations
  • LiveTable
  • Channel
  • Jobs
  • Email
  • Payments
  • JSON
  • Async
  • Style
  • UI
    • Templates
    • Behaviors
    • Themes
  • JSOC
  • Config
  • Tests
  • Logs
  • Deploy
  • Editors
  • Recipes
  • Licenses
Manual / UI/ Templates/ AspectRatio

AspectRatio

elements man ui/templates/aspect-ratio

Keeps media at a fixed width-to-height ratio, with its space held before it loads.

Example
import { AspectRatio } from "@elements/ui/aspect-ratio"; <AspectRatio ratio={16 / 9}> <img src="./hero.jpg" alt="A mountain lake at dawn"> </AspectRatio>

Parts

Part What it is
.aspect-ratio The box. Usable without the template: style="aspect-ratio: 16 / 9".

Attributes

Attribute Type Default Description
ratio number 1 Width divided by height: 16 / 9, 1, 9 / 16.
fit "cover" | "contain" | "fill" "cover" object-fit for an image or video child.
class string "" Extra classes: rounded corners, a background.
attrs Record<string, string | number | boolean | undefined> {} Any other attributes: id, role, aria-*, data-*.

Slots

Slot Content
default The media or content; each child fills the box.

Data attributes

Attribute Values On
data-ratio the ratio root
data-fit "cover" | "contain" | "fill" root

Accessibility

  • No role of its own: the image inside carries the meaning through its alt text.
  • The box holds its height before the media loads, so content below it never jumps.

See also

  • Badge (opens in a new tab): A small label for a status, a count or a category, built on the pill.
  • Card (opens in a new tab): A surface with a header, body and footer, built on the base card styles.
  • Alert (opens in a new tab): A callout that draws attention to a message, with an icon, a title and an action.
  • Icon (opens in a new tab): An inline stroke icon from the set the templates draw their own controls with, sized in pixels and colored by the text around it.
  • Kbd (opens in a new tab): A keyboard key or shortcut, as text.
  • Separator (opens in a new tab): A horizontal or vertical rule between content, semantic or decorative.
Prev ProgressNext Avatar
Product
Manual Pricing Compare
Company
History Contact
Legal
Privacy Policy Acceptable Use Terms License Agreement
© Elements Dev Corporation 2026