Reference

Image

Image; alt is required for accessibility (rule A01). Given an image the program declares, it becomes a <picture> with every width the build wrote.

Image(_ source: Picture or String, src: String, sizes: String, placeholder: Enum, …)

Before 5.0

src

sizes

placeholder

blur

color

none

alt

WebFluent's sharing card: the name over a dark field
The app icon

Pictures from public/ are resized to WebP at every width a page asks for.

Example

wf

Stack(gap: .md) { Image(src: "/og.png", alt: "WebFluent's sharing card: the name over a dark field", sizes: "(max-width: 768px) 100vw, 640px", placeholder: .blur).rounded Row(gap: .md, align: .center) { Image(src: "/icon-512.png", alt: "The app icon", width: 64, height: 64).circle Text("Pictures from public/ are resized to WebP at every width a page asks for.").muted.sm } }

Decorative: an empty alt, so a screen reader skips it

wf

Image(src: "/icon-512.png", alt: "", width: 32, height: 32)

The average colour while it loads, and loaded at once

wf

Image(src: "/og.png", alt: "The sharing card", placeholder: .color, loading: .eager)

From an address elsewhere: used as written

wf

Image(src: "https://example.com/team.jpg", alt: "The team at the launch", width: 1200, height: 630).lazy

Props

Props of Image
PropTypeUnsetMeaning

source

Picture or String (positional)

none

An image the program declares (a <picture> at every width the build wrote), or a URL

src:

String

none

The picture's address. A literal path of public/ to a PNG, JPEG, GIF or WebP is processed by the build like an image; an SVG, a URL or a data:image/… is used as written

sizes:

String

none: the browser assumes the full window width

How wide it will be shown, so the browser picks one of the widths the build wrote: (max-width: 768px) 100vw, 1200px; for a processed picture

placeholder:

one of its cases

none

What fills the box of a processed picture while it loads, cleared when it lands. Written as a flag, .blur, or by name, placeholder: .blur.

  • .blur: A 16-pixel-wide blurred copy, inlined in the page
  • .color: The picture's average colour
  • .none (the default): Nothing (the default)

alt:

String

none ("" on a processed picture)

Text alternative; "" for a purely decorative image (A01 when left out)

width:

Number

none

The <img>'s width in px, so its box is reserved before it loads; ignored on a processed picture, which carries the file's real size

height:

Number

none

The <img>'s height in px, so its box is reserved before it loads; ignored on a processed picture, which carries the file's real size

loading:

one of its cases

the page's first image eager at high priority, the rest lazy

When the browser fetches it. Written as a flag, .lazy, or by name, loading: .lazy.

  • .lazy: When it nears the viewport
  • .eager: At once

shape:

one of its cases

none: square corners

Its corners. Written as a flag, .rounded, or by name, shape: .rounded.

  • .rounded: Rounded corners (radius-md)
  • .circle: Clipped to a circle (an ellipse, unless it is square)

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.

.blur

.color

.none

.lazy

.eager

.rounded

.circle

Events

The DOM events it is drawn to answer. Any other DOM event works too, in an on … { } handler.

DOM events Image answers
EventSendsMeaning
on loadDOMAn image, video or frame finished loading
on errorDOMAn image, video or script failed to load

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

Slots

It takes no slots.

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