ContentImage renders images that participate in document flow - the image controls its own dimensions and pushes surrounding content out of the way, just like a paragraph or heading. No object-fit styling is applied; the image renders at its natural aspect ratio.
Use ContentImage when the image is the content: article photos, product shots, thumbnails, inline figures, or any image whose intrinsic size matters to the layout.
ContentImage vs CoverImage
ContentImage - the image controls its size (inline flow, natural aspect ratio).
CoverImage - the container controls the size (backdrop, object-fit: cover, crops to fill).
If your image sits inside a fixed-height box and content overlays it, you want CoverImage . If the image flows naturally alongside text, you want ContentImage.
npx shadcn@latest add @rokkit200-ui/content-image The image below flows naturally within the article body. It renders at its intrinsic aspect ratio and the surrounding text wraps around it - the image controls its own size.
This is a ContentImage - use it when the image is the content: article photos, product shots, thumbnails, or any image that participates in document flow.
import { ContentImage } from " @/registry/rokkit200-ui/components/content-image/content-image " ;
} from " @/registry/rokkit200-ui/components/image/image-types " ;
* A demo-only URL builder for placehold.co that rewrites the path-encoded
* dimensions and appends a text label showing the requested width.
* This makes each srcset candidate visually distinct so you can resize
* the browser and see the browser pick a different resolution.
const placeholdDemoBuilder : ImageUrlBuilder = {
return new URL (image . src ) . hostname . endsWith ( " placehold.co " ) ;
build : ( image , transform : UrlTransform ) => {
const url = new URL (image . src ) ;
const w = (transform . width as number | undefined ) ?? image . width ;
(transform . height as number | undefined ) ??
(w != null && image . width && image . height
? Math . round (w * (image . height / image . width ))
// Rewrite the leading /WxH segment
url . pathname = url . pathname . replace ( / ^ \/ \d + x \d + / , ` / ${ w } x ${ h } ` ) ;
// Stamp the requested width as visible text on the placeholder
url . searchParams . set ( " text " , ` ${ w } x ${ h } ` ) ;
const image : NormalizedImageSource = {
src: " https://placehold.co/800x500 " ,
alt: " Photograph of a mountain landscape used as an inline content image " ,
const profile : PictureProfile = {
srcSetWidths: [ 400 , 600 , 800 ] ,
sizes: [ " (max-width: 600px) 100vw " , " 800px " ] ,
* ContentImage renders an inline, document-flow image whose dimensions are
* controlled by the image itself - not by its container. The image pushes
* surrounding content out of the way, just like a paragraph or heading.
* Typical uses: article photos, product shots, thumbnails, inline figures.
export default function ContentImageDefaultDemo () {
< article className = " text-muted-foreground mx-auto max-w-prose space-y-4 text-sm " >
The image below flows naturally within the article body. It renders at
its intrinsic aspect ratio and the surrounding text wraps around it -
the image controls its own size.
urlBuilder = { placeholdDemoBuilder }
This is a < strong > ContentImage </ strong > - use it when the image { " " }
< em > is </ em > the content: article photos, product shots, thumbnails, or
any image that participates in document flow.
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 content images use <picture> with multiple sources. The imageClassName prop targets the inner <img> element while className applies to the <picture> wrapper. For more on Art Directed images and the <picture> element, see here .
import { ContentImage } from " @/registry/rokkit200-ui/components/content-image/content-image " ;
} from " @/registry/rokkit200-ui/components/image/image-types " ;
import { unsplashUrlBuilder } from " @/registry/rokkit200-ui/components/image/image-url-builder " ;
type ProfileKey = " default " | " desktop " | " tablet " | " mobile " ;
const artDirectedSources : ArtDirectedImageSource < ProfileKey > = {
src: " https://images.unsplash.com/photo-1682687220742-aba13b6e50ba " ,
metadata: { alt: " Art-directed content image " },
media: " (min-width: 1920px) " ,
src: " https://images.unsplash.com/photo-1506905925346-21bda4d32df4 " ,
media: " (min-width: 1280px) " ,
src: " https://images.unsplash.com/photo-1470071459604-3b5ec3a7fe05 " ,
media: " (min-width: 768px) " ,
src: " https://images.unsplash.com/photo-1464822759023-fed622ff2c3b " ,
const profileMap : Record < ProfileKey , PictureProfile > = {
srcSetWidths: [ 400 , 600 , 800 ] ,
srcSetWidths: [ 1280 , 1600 , 1920 ] ,
srcSetWidths: [ 768 , 1024 , 1280 ] ,
srcSetWidths: [ 480 , 600 , 768 ] ,
export default function ContentImageArtDirectedDemo () {
artDirectedImageSource = { artDirectedSources }
urlBuilder = { unsplashUrlBuilder }
className = " overflow-hidden rounded-lg "
imageClassName = " w-full object-cover "
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.
import { ContentImage } from " @/registry/rokkit200-ui/components/content-image/content-image " ;
} from " @/registry/rokkit200-ui/components/image/image-types " ;
const image : NormalizedImageSource = {
src: " https://images.unsplash.com/photo-1531366936337-7c912a4589a7 " ,
alt: " Content image with a CMS-provided srcSet override " ,
* Profile with empty srcSetWidths - the planner won't generate its own srcset.
* Sizes are still required so the overridden width-descriptor srcset works.
const profile : PictureProfile = {
sizes: [ " (max-width: 600px) 100vw " , " 800px " ] ,
* A pre-built srcset string, as might be provided by a CMS.
* Because it uses width descriptors (`w`), ContentImage validates that
* sizes are resolvable before forwarding the override to the planner.
" https://images.unsplash.com/photo-1531366936337-7c912a4589a7?w=400 400w " ,
" https://images.unsplash.com/photo-1531366936337-7c912a4589a7?w=600 600w " ,
" https://images.unsplash.com/photo-1531366936337-7c912a4589a7?w=800 800w " ,
export default function ContentImageSrcSetOverrideDemo () {
srcSetOverride = { cmsSrcSet }
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.
import { ContentImage } from " @/registry/rokkit200-ui/components/content-image/content-image " ;
} from " @/registry/rokkit200-ui/components/image/image-types " ;
* Image with no alt text in metadata and no alt prop override.
* The planner emits a dev warning for non-decorative images with empty alt.
* Open the browser console to see:
* [image] Non-decorative image has empty alt text.
const image : NormalizedImageSource = {
src: " https://images.unsplash.com/photo-1506905925346-21bda4d32df4 " ,
const profile : PictureProfile = {
srcSetWidths: [ 300 , 600 ] ,
sizes: [ " (max-width: 600px) 100vw " , " 600px " ] ,
export default function ContentImageWarnEmptyAltDemo () {
return < ContentImage imageSource = { image } profile = { profile } /> ;
An image without width / height triggers a dev warning. Pass suppressMissingDimensionsWarning for intentionally dimension-free images such as SVGs or data URIs.
import { ContentImage } from " @/registry/rokkit200-ui/components/content-image/content-image " ;
} from " @/registry/rokkit200-ui/components/image/image-types " ;
* Image deliberately missing width and height - common for SVGs or data URIs.
* The planner emits a dev warning when dimensions are absent.
* Open the browser console to see:
* [image] Image is missing width.
const image : NormalizedImageSource = {
src: " https://images.unsplash.com/photo-1506905925346-21bda4d32df4 " ,
alt: " Image without explicit dimensions " ,
const profile : PictureProfile = {
srcSetWidths: [ 300 , 600 ] ,
sizes: [ " (max-width: 600px) 100vw " , " 600px " ] ,
export default function ContentImageWarnMissingDimensionsDemo () {
return < ContentImage imageSource = { image } profile = { profile } /> ;
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.
import { ContentImage } from " @/registry/rokkit200-ui/components/content-image/content-image " ;
} from " @/registry/rokkit200-ui/components/image/image-types " ;
* Profile with srcSetWidths but no sizes. When w descriptors are generated
* but sizes cannot be resolved, the planner discards the srcset and emits
* Open the browser console to see:
* [image] Profile "warn-missing-sizes" has no sizes defined and no sizes
* override was provided. srcset with w descriptors requires sizes -
* srcset will be omitted.
const image : NormalizedImageSource = {
src: " https://images.unsplash.com/photo-1506905925346-21bda4d32df4 " ,
alt: " Image with a profile missing sizes " ,
const profile : PictureProfile = {
id: " warn-missing-sizes " ,
srcSetWidths: [ 300 , 600 ] ,
export default function ContentImageWarnMissingSizesDemo () {
return < ContentImage imageSource = { image } profile = { profile } /> ;
Below is an example of how to use ContentImage in your site.
import { ContentImage } from " @/rokkit200-ui/components/content-image/content-image " ;
{ /* Inline image in an article - the image controls its own size */ }
src: " /photos/article-photo.jpg " ,
metadata: { alt: " Article photo " },
srcSetWidths: [ 400 , 600 , 800 ] ,
sizes: [ " (max-width: 600px) 100vw " , " 800px " ] ,
Both ContentImage and CoverImage 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 )) ;
Prop Type Default Description urlBuilderImageUrlBuilderpassthrough CDN-specific URL builder for rewriting image URLs with transforms. Auto-detected when omitted.
Prop Type Default Description 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.
Prop Type Default Description 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.
Prop Type Default Description 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 content images. Optional. urlBuilderImageUrlBuilderpassthrough CDN-specific URL builder. 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). 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.