Image
An image in a box of fixed proportions, with a placeholder behind it.
Default
<div class="max-w-md">
{ui image,
src: p('images')->image('ultralight-img-1975.jpeg')->src('w=800'),
alt: 'A mountain ridge at dawn',
/}
</div>
The box has a fixed ratio, 16 / 9 unless ratio says otherwise, and the image fills it and crops to fit. Because the box is sized before the image arrives, the page does not jump as images load. src is a URL, so a page's file is p('page')->image('photo.jpg')->src('w=800'). Set alt to what the image shows, and leave it empty when it only decorates. The image loads lazily; set lazy: false for the one at the top of the page.
Ratio and focus
<div class="flex items-start gap-4">
{ui image,
src: p('images')->image('ultralight-img-1975.jpeg')->src('w=600'),
alt: 'A mountain ridge at dawn',
ratio: '2 / 3',
focus: '30% 50%',
class: 'w-40',
/}
{ui image,
src: p('images')->image('ultralight-img-1975.jpeg')->src('w=600'),
alt: 'A mountain ridge at dawn',
ratio: '1 / 1',
class: 'w-40',
/}
</div>
ratio is the box's width / height, such as '2 / 3' for a book cover or '1 / 1' for a square. When a crop cuts the image, focus picks the part to keep, as an object-position: '50% 30%' keeps the upper middle, which saves a face in a portrait. The width comes from the box around it or a class such as w-40.
Placeholder and contain
<div class="flex items-start gap-4">
{ui image,
ratio: '4 / 3',
placeholder: 'hsl(var(--primary))',
class: 'w-40',
/}
{ui image,
src: p('images')->image('ultralight-img-1975.jpeg')->src('w=600'),
alt: 'A mountain ridge at dawn',
ratio: '4 / 3',
class: 'image-contain w-40',
/}
</div>
placeholder is a CSS background drawn behind the image until it paints: a color, or a url() of a small blurred copy. It is a muted fill when left out, and it is all that shows when there is no src. class: 'image-contain' fits the whole image inside the box instead of cropping it, and the placeholder shows in the space around it. Round corners come from the theme's radius, and rounded-none or rounded-full changes them.