Skip to content

Cover Image

CoverImage renders images that fill a container - the container dictates the dimensions and the image stretches and crops to cover it with object-fit: cover applied by default. Think of it as the accessible, SEO-friendly replacement for background-image: cover.

Use CoverImage when the image is a backdrop: hero banners, card backgrounds, split-layout panels, full-bleed sections, or anywhere a fixed-size container needs an image filling it edge to edge.

Aerial cityscape used as a hero banner background

Hero Banner

The container controls the size - the image stretches and crops to fill it.

This preview uses placehold.co with a demo-only URL builder that rewrites each generated image candidate and stamps the requested dimensions into the image text. That makes each srcset candidate visually distinct, so when you resize the browser you can clearly see the browser switching to a different resolution.

Art-directed cover images use <picture> with multiple sources for different breakpoints. Each source can provide a different crop or aspect ratio suited to the viewport.

Art-directed cover image

Hero Banner

The container controls the size - the image stretches and crops to fill it.

Override the default object-position: center when the focal point of the image is off-center. This example shows top-right positioning.

Cover image with custom object-position - the focal point is offset toward the top-right

Hero Banner

The container controls the size - the image stretches and crops to fill it.

Bypass the planner-generated srcset with a pre-built string (e.g. from a CMS). Width descriptors are validated against resolvable sizes - if sizes cannot be resolved, the override is discarded with a dev warning.

Cover image with a CMS-provided srcSet override

Hero Banner

The container controls the size - the image stretches and crops to fill it.

A non-decorative image with no alt text triggers a dev warning. Either provide an alt prop, populate metadata.alt on the source, or mark the image as decorative.

Hero Banner

The container controls the size - the image stretches and crops to fill it.

An image without width / height triggers a dev warning. Pass suppressMissingDimensionsWarning for intentionally dimension-free images such as SVGs or data URIs.

Cover image without explicit dimensions

Hero Banner

The container controls the size - the image stretches and crops to fill it.

A profile with srcSetWidths but no sizes causes the planner to discard the generated srcset and emit a dev warning. Provide sizes on the profile or via the sizes prop.

Cover image with a profile missing sizes

Hero Banner

The container controls the size - the image stretches and crops to fill it.

Below is an example of how to use CoverImage in your site.

import { CoverImage } from "@/rokkit200-ui/components/cover-image/cover-image";
{/* Hero banner - the container controls the size, image fills it */}
<div className="relative h-96 w-full">
<CoverImage
imageSource={{
src: "/photos/hero-banner.jpg",
width: 1200,
height: 600,
metadata: { alt: "Hero banner" },
}}
profile={{
id: "hero",
srcSetWidths: [600, 900, 1200],
sizes: ["100vw"],
}}
/>
<div className="relative z-10 p-8">
<h1>Your heading over the cover image</h1>
</div>
</div>

Both CoverImage and ContentImage accept an optional urlBuilder prop — an implementation of ImageUrlBuilder that rewrites image URLs with CDN-specific transforms (width, height, quality, format, etc.) at render time.

Three built-in builders are provided:

  • optimizelyUrlBuilder — Optimizely CMP / DAM
  • cloudflareUrlBuilder — Cloudflare Image Resizing
  • unsplashUrlBuilder — Unsplash (Imgix-backed)

If no urlBuilder is passed, resolveUrlBuilder auto-detects the CDN from the image URL. Pass a builder explicitly when auto-detection isn’t possible or when you need a custom implementation.

Implement the ImageUrlBuilder interface exported from image-types:

import type { ImageUrlBuilder } from "@/rokkit200-ui/components/image/image-types";
const myBuilder: ImageUrlBuilder = {
supportedFormats: ["auto", "webp", "jpg"],
canHandle: image => new URL(image.src).hostname === "cdn.example.com",
build: (image, transform) => {
const url = new URL(image.src);
if (transform.width != null)
url.searchParams.set("w", String(transform.width));
if (transform.height != null)
url.searchParams.set("h", String(transform.height));
return url.toString();
},
};
PropTypeDefaultDescription
urlBuilderImageUrlBuilderpassthroughCDN-specific URL builder for rewriting image URLs with transforms. Auto-detected when omitted.
PropTypeDefaultDescription
imageSourceNormalizedImageSource—The image data object (src, width, height, metadata). Required (XOR with art-directed props).
profilePictureProfile—Responsive profile controlling srcset widths, sizes, format, quality, and fit. Required with imageSource.
sizesstring—Override sizes from the profile for this specific instance. Optional.
PropTypeDefaultDescription
artDirectedImageSourceArtDirectedImageSource<K>—Fallback image plus breakpoint-specific sources for <picture> rendering. Required (XOR with normalized props).
profileMapRecord<K, PictureProfile>—Map of profile keys to profiles, one per source entry. Required with artDirectedImageSource.
PropTypeDefaultDescription
altstring—Override alt text. Falls back to imageSource.metadata.alt. Optional.
decorativebooleanfalseMark as decorative (renders alt=""). Optional.
loading"lazy" | "eager""lazy"HTML loading strategy. Optional.
fetchPriority"high" | "low" | "auto"—Fetch priority hint for the browser. Optional.
decoding"async" | "sync" | "auto""async"Decoding strategy. Defaults to async for cover images. Optional.
urlBuilderImageUrlBuilderpassthroughCDN-specific URL builder. Optional.
objectPositionClassNamestring"object-center"CSS object-position applied to the <img>. Shift the crop focal point away from center. Optional.
classNamestring—Applied to the outermost element (<img> or <picture>). Optional.
styleReact.CSSProperties—Inline styles on the outermost element. Optional.
imageClassNamestring—Applied to the <img> inside <picture> (art-directed only). Composed with object-cover by default. Optional.
imageStyleReact.CSSProperties—Inline styles on the <img> inside <picture>. Optional.
srcSetOverridestring—Bypass planner-generated srcset with a pre-built string. Width descriptors require resolvable sizes or the override is discarded. Optional.
suppressWarningsbooleanfalseSilence all dev warnings. Optional.
suppressMissingDimensionsWarningbooleanfalseSilence the missing-dimensions warning only. Optional.
suppressMissingSizesWarningbooleanfalseSilence the missing-sizes warning only. Optional.
suppressEmptyAltWarningbooleanfalseSilence the empty-alt warning only. Optional.