Skip to content
Overlay ColorModeImage

ColorModeImage

An image with one source per color mode.

On this page

Examples

Color mode image

A sun by day, a moon by night
Razor
<KlyColorModeImage Light="@Scene("#fef3c7", "#f59e0b")" Dark="@Scene("#0f172a", "#e2e8f0")" Alt="A sun by day, a moon by night"
                  width="320" height="160" Class="rounded-lg" data-testid="color-mode-image" />

@code {
    // Two SVG pictures stand in for two real image files.
    private static string Scene(string sky, string body) =>
        "data:image/svg+xml," + Uri.EscapeDataString(
            $"<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 320 160'><rect width='320' height='160' fill='{sky}'/><circle cx='160' cy='80' r='34' fill='{body}'/></svg>");
}

API

KlyColorModeImage

Image with one source for light mode and one for dark mode. CSS shows the matching one, so there is no flash.

Parameters

Name Type Description
Alt string Text alternative. Leave empty for a decorative image.
Class string Classes added to the root element, merged last so they win over the theme.
Dark string Image in dark mode. Defaults to Light .
Height int? Height of both images in CSS pixels, see Height .
ImageOptions KlyImageOptions Image settings forwarded to both light and dark images.
Light (required) string Image in light mode.
Width int? Width of both images in CSS pixels, see Width .