Image
Synonyms: Img, Thumbnail
Description: The Image component renders images and supports responsive display with different resolutions, pixel densities, and file formats. It provides optimized loading through lazy loading and ensures full accessibility with alternative texts.
Example
Basic display of an image with the required alternative text:
<KolImage _alt="Sample image" _loading="lazy" _src="/assets/sample-image.png" />Accessibility
- Alternative text required: The
_altattribute is mandatory and is read by screen readers. For purely decorative images it can be empty (_alt=""), which causes assistive technologies to ignore it. - Fallback for missing images: The alternative text is displayed by browsers if the image cannot be loaded or is unavailable.
- Semantically correct: The component uses native HTML5
<img>elements and supports all standard image formats and browser features.
Links and References
Usage
Best Practices / Recommendations
- Meaningful alternative texts: Write concise descriptions that convey the content and purpose of the image. Avoid "Image of..." or generic descriptions.
- Decorative images: Leave
_altempty for purely decorative images that carry no semantic information. - Responsive images: Use
_srcsetand_sizesfor different device resolutions and pixel densities to save bandwidth and deliver sharp images on high-resolution displays. - Modern file formats: Use
_srcsetwith different file formats (e.g. WebP for modern browsers, JPEG as fallback) to optimize performance. - Use lazy loading: Set
_loading="lazy"for images outside the initial viewport to improve page loading performance. - Eager loading for critical images: Use
_loading="eager"only for images in the visible area (e.g. logo, hero image) that should be loaded immediately.
Use Cases
- Product images and galleries in e-commerce applications
- User photos and avatars (in combination with other components)
- Illustrations and icons to visualize content
- Hero images and banner graphics on landing pages
- Responsive images in articles, blog posts or documentation
- Background images and branding elements
FAQ
When should I use _srcset? Use _srcset when you want to provide the same image in different resolutions or sizes. This allows browsers to select the best variant based on device resolution and viewport size.
What is the difference between _loading="eager" and _loading="lazy"? eager loads the image immediately when the page loads. lazy delays loading until just before the image appears in the viewport. lazy is the default and improves page loading performance.
Can I use arbitrary image formats? Yes, all common formats are supported (PNG, JPEG, WebP, SVG, GIF etc.). Use _srcset with different formats for maximum browser compatibility and performance.
Construction / Technical
Playground
<KolImage _alt="Sample image" _loading="lazy" _src="/assets/sample-image.png" />Features (with Code)
Image source
The image source is set via the required _src attribute. This is the fallback URL used when _srcset is not supported or no suitable variant is available.
<KolImage _alt="Sample image" _loading="lazy" _src="/assets/sample-image.png" />Alternative text
The required _alt attribute provides a text description or alternative for the image. For decorative images it can be empty.
<KolImage _alt="Example image description" _loading="lazy" _src="/assets/sample-image.png" />Responsive images with Srcset and Sizes
With _srcset different image versions can be specified for different resolutions, pixel densities and file formats. The _sizes attribute helps the browser understand what widths the image will have at different viewport sizes.
<KolImage _alt="Sample image" _loading="lazy" _sizes="(max-width: 600px) 100vw, 50vw" _src="/assets/sample-image.png" _srcset="/assets/image-small.png 600w, /assets/image-large.png 1200w" />Loading behavior
The _loading attribute controls when the browser loads the image. lazy is the default and improves performance, eager should only be used for images in the visible area.
<KolImage _alt="Sample image" _loading="lazy" _src="/assets/sample-image.png" />Available values:
lazy: Defers loading until the viewport is reached (default)eager: Immediate loading when entering the page
API
Overview
The Image component renders an image with support for responsive loading via srcset and sizes, lazy loading, and accessible alternative text.
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
_alt (required) | _alt | Sets the alternative text of the image. | string | undefined |
_loading | _loading | Defines the loading mode for the image. | "eager" | "lazy" | undefined | undefined |
_sizes | _sizes | Defines the image sizes for different screen resolutions, supporting _srcset. | string | undefined | undefined |
_src (required) | _src | Sets the image src attribute to the given string. | string | undefined |
_srcset | _srcset | Sets a list of source URLs with widths of the images. | string | undefined | undefined |