Vanilla Breeze

data-mock

Placeholder media via data attributes. Add data-mock to img, video, iframe, or canvas for instant placeholder boxes with X-pattern, presets, and photo service integration.

Overview

The data-mock attribute turns native media elements into placeholder boxes. CSS renders the visual (gray box, X-pattern) and JS generates a valid src to keep the element well-formed. Moving to production means replacing src and removing data-mock — no HTML restructuring.

How It Works

  1. CSS applies a gray background, dashed border, and diagonal X-pattern via gradients
  2. JS generates an inline SVG data URI as src (for <img>), poster (for <video>), srcdoc (for <iframe>), or draws on <canvas>
  3. The label text comes from the alt attribute (images), title (iframes), or aria-label (canvas)
  4. Named presets set aspect ratio and default dimensions via CSS — no width/height attributes needed

Attributes

Attribute Type Description
data-mock string Preset name (hero, card, avatar, etc.) or empty for generic placeholder. Special values: photo (picsum), placehold (placehold.co).
data-seed string Reproducible seed for photo (picsum) and portrait/avatar/headshot presets. Same seed always returns the same image.
data-mock-init boolean Set automatically to prevent double-binding. Do not set manually.

Presets

Named presets set aspect-ratio and a default inline-size via CSS. Explicit width/height attributes override the JS dimensions used for SVG generation.

PresetAspect RatioDefault WidthUse Case
hero3:1100%Hero banners
card16:9400pxBlog/article cards
avatar1:148pxUser avatars — uses portrait photo
portrait1:1128pxPerson portrait photo
profile1:1128pxProfile photo (alias for portrait)
headshot1:1256pxLarger portrait for bios, team pages
product1:1400pxProduct images
thumbnail1:1150pxGrid thumbnails
logo4:1200pxBrand logos
og1200:630100%Open Graph images
banner728:90100%Ad banners
Hero banner Card image User avatar Thumbnail Logo

Photo Service

Use data-mock="photo" for realistic placeholder photos from picsum.photos. The image dimensions come from width and height attributes.

Add data-seed for reproducible results — the same seed always returns the same photo.

Placehold.co

Use data-mock="placehold" for labeled placeholder images from placehold.co. The alt text is used as the label.

Person Portraits

The portrait, avatar, profile, and headshot presets generate realistic AI-generated face photos from the faker-js portrait CDN (CC0 licensed). The face is deterministic — the same data-seed or alt text always produces the same person.

Alice Morgan
avatar
Ben Torres
portrait
Chloe Park
headshot

Programmatic API

Use the VanillaBreeze.mock.portraitUrl() function for dynamic scenarios.

Iframe

Gets a srcdoc with a minimal HTML page showing a centered label. Defaults to 16:9 with min-height 300px.

Canvas

Draws the X-pattern and label directly on the canvas context. Defaults to 4:3 aspect ratio.

Inside Figure

Works inside <figure> and <picture> with no structural changes needed.

Team photo
Our engineering team

Production Transition

Moving to production requires no HTML restructuring. Replace src and remove data-mock.

Styling

The placeholder colors use design tokens (--color-gray-200, --color-gray-400). Override them with element-scoped CSS.

Wireframe Integration

When inside a [data-wireframe] container, mock media automatically adapts to wireframe tokens (--wireframe-fill, --wireframe-stroke, --wireframe-border). No extra configuration needed.

Dynamic Elements

Elements added to the DOM after page load are automatically enhanced via a MutationObserver.