Skip to content
Content Blocks docsv0.8.0Website

Docs / Elements

<content-image>

A responsive image or muted looping video per breakpoint with native lazy loading.

Import it on its own, for a bundler
import '@content-blocks/js/components/content-image';

Examples

A crop per breakpoint

A tall 4:5 photo on phones and a wide 16:9 one from 768px, each from its own source.

Open on its own

Anatomy

Content goes into the component's slots, chosen with the slot attribute on each child.

flowchart LR
  root["#lt;content-image#gt;"]:::component
  root --> s0["<b>slot=#quot;mediaContent#quot;</b><br/>Content displayed over media. If you want to reveal content on hover,…"]
  classDef component fill:#141413,color:#faf9f5,stroke:#141413
The slots of <content-image>
SlotWhat goes in it
slot="mediaContent"Content displayed over media. If you want to reveal content on hover, use a tout block

Properties

Set them as attributes. Those marked responsive take a value per breakpoint, separated by pipes and named or in order: 1|tablet=2 or 1|2. Seeresponsive values.

AttributeTypeDefaultDescription
altresponsiveString–Not documented yet
aspect-ratioresponsiveString–Not documented yet
classesresponsiveString–Classes to add to the component. Use pipes for different classes per breakpoint, by name or in order: classes="stacked|laptop=side-by-side".
fetch-prioritySelect

auto · high · low

–How soon the browser should download the image compared with other files. Use "high" for the main image of the page.
heightresponsiveNumber'9'Not documented yet
lazy-loadBooleantrueImages use the browser's native lazy loading. Set to false for images that are visible when the page opens, such as a hero, so they download straight away.
paddingresponsiveString–Padding around the component, written as CSS padding. Use pipes for different padding per breakpoint, by name or in order: padding="1rem|tablet=2rem 4rem" or padding="1rem|2rem 4rem|3rem 5rem 4rem".
show-contentresponsiveBoolean'false|true'If true, the content in the mediaContent slot will be visible.
srcresponsiveMedia–Not documented yet
typeSelect

image · video

'image'Not documented yet
video-typeSelect

video/mp4

'video/mp4'Not documented yet
widthresponsiveNumber'16'Not documented yet
flowchart LR
  v["aspect-ratio=#quot;4/5|16/9#quot;"]:::value
  v --> b0["mobile, from 0px: 4/5"]
  v --> b1["tablet and up, from 768px: 16/9"]
  classDef value fill:#1d4ed8,color:#fff,stroke:#1d4ed8
How aspect-ratio="4/5|16/9" from the examples applies at each breakpoint