Image

En/ Ru

Image

Image renders accessible img, picture, and source primitives.

github.com/fastygo/templ/ui

Summary

Image renders accessible img, picture, and source primitives.Use Decorative for purely visual images.

Use Cases

    Render product screenshots, avatars, logos, and thumbnails

    Render responsive image sources with picture

Semantics

    Decorative images render an empty alt and aria-hidden true

    Image defaults to loading lazy and decoding async

Example variant.avatar

User avatar
import "github.com/fastygo/templ/ui"

templ Example() {
	@ui.Image(ui.ImageProps{Variant: "avatar", Size: "md", Src: "/avatar.png", Alt: "User avatar"})
}

Example layout.picture

Hero image
import "github.com/fastygo/templ/ui"

templ Example() {
	@ui.Picture(ui.PictureProps{}) {
		@ui.Source(ui.SourceProps{SrcSet: "/hero.webp", Type: "image/webp"})
		@ui.Image(ui.ImageProps{Variant: "rounded", Src: "/hero.jpg", Alt: "Hero image"})
	}
}

API

Aspect · string — role: aspect-ratio; enum: auto|square|video; default: auto

Decorative · bool — role: accessibility

Fit · string — role: object-fit; enum: contain|cover|fill|none|scale-down; default: cover

Position · string — role: object-position; enum: bottom|center|left|right|top|left-bottom|left-top|right-bottom|right-top; default: center

Size · string — role: density; enum: auto|default|xs|sm|lg|xl|full; default: auto; source: ui.image.ImageVariants

Variant · string — role: appearance; enum: default|rounded|avatar|thumbnail|logo|unstyled; default: default; source: ui.image.ImageVariants