Display
Image
A responsive image that reserves its space (no layout shift), loads lazily, and preloads the one above-the-fold image.
<script>
import { Image } from "@codeatlasdev/ui";
</script>
<Image src="/hero.avif" alt="Dashboard overview" width={1200} height={630} priority />
width and height are the intrinsic pixel size of the file. The browser derives the aspect ratio from them before the image arrives, so nothing jumps when it loads, and max-width: 100% with height: auto keeps that ratio on small screens. Images are loading="lazy" and decoding="async" by default.
Use priority on the one image that is the largest thing visible on first paint (the LCP element). It loads eagerly, sets fetchpriority="high" and adds a <link rel="preload" as="image"> to <head>. Never put it on more than one image per page.
Fixed ratio
The 800 by 600 file renders at 360px wide and keeps its 4:3 box.
Code
srcset and sizes
The browser picks the smallest rendition that covers the rendered width.
Code
For AVIF and WebP generation at build time see Performance.
Alt text
alt is required. An image that carries no meaning passes decorative instead of alt=""; it renders alt="" with aria-hidden="true". In development the component warns when alt="" is passed without decorative, when width or height is missing, and when decorative is combined with a non-empty alt.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | – | Image URL. |
alt | string | – | Text alternative. Required; use `decorative` for decoration. |
width | number | – | Intrinsic width in pixels. Required, with `height` it reserves the space. |
height | number | – | Intrinsic height in pixels. Required. |
decorative | boolean | false | Renders `alt=""` and `aria-hidden="true"`. |
priority | boolean | false | Eager load, `fetchpriority="high"` and a preload link in `<head>`. One per page, for the LCP image. |
loading | 'lazy' | 'eager' | 'lazy' ('eager' with priority) | Overrides the default. |
decoding | 'async' | 'sync' | 'auto' | 'async' | Decode hint. |
class | string | '' | Extra class names. |
Other <img> attributes are forwarded as they are. srcset and sizes are the ones you will use most: srcset lists the candidate renditions and sizes tells the browser the rendered width. With priority, both are copied onto the preload link in <head>. fetchpriority is controlled by priority.