Reference

AspectRatio

A box that keeps its shape as its width changes — ratio: 16 / 9 — its child filling it: a picture, a video, a frame.

AspectRatio(ratio: Number) { … }

Since 6.2.0

The WebFluent card, in 16:9
The WebFluent icon, square

Example

wf

Grid(columns: 2, gap: .md) { AspectRatio(ratio: 16 / 9) { Image(src: "/og.png", alt: "The WebFluent card, in 16:9") } AspectRatio(ratio: 1) { Image(src: "/icon-512.png", alt: "The WebFluent icon, square") } }

A box for a frame

wf

AspectRatio(ratio: 4 / 3) { Center { style { background: $color-surface; border: 1px dashed $color-border } Text("4 : 3").muted } }

Props

Props of AspectRatio
PropTypeUnsetMeaning

ratio:

Number (required)

—

Its width over its height, 16 / 9 (CSS aspect-ratio): a literal is a rule of the sheet, one that reads state follows it

Attribute families: global, aria, data. Plus the 22 universal props every element takes: animate:, exit:, speed:, duration:, delay:, easing:, stagger:, on:, count:, shared:, class:, ref:, drag:, dragGroup:, dropValue:, dropAxis:, dropInside:, roving:, trapFocus:, mount:, update:, cleanup:.

Flags and cases

A flag is written after the parentheses with a dot: a Bool prop, or a case of one of the element's enum props. A case the enum lacks is an error with a hint.

No flags of its own.

Events

Every element also takes the props, the events and the attribute families listed on every element.

Slots

children

Renders with the class wf-aspect-ratio, stable across releases, so a stylesheet may target it.

These controls list the props' cases; the example below shows them written.