<content-image>
A responsive image or muted looping video per breakpoint with native lazy loading.
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.
<content-image
alt="A bearded warrior in a steel helm"
src="https://images.unsplash.com/photo-1525540796810-55f9fbc5592f?w=800&h=1000&fit=crop&auto=format&q=75|https://images.unsplash.com/photo-1525540796810-55f9fbc5592f?w=1600&h=900&fit=crop&auto=format&q=75"
aspect-ratio="4/5|16/9"
></content-image>// $ npm install @content-blocks/js
import '@content-blocks/js/components/content-image';<script type="module"
src="https://cdn.jsdelivr.net/npm/@content-blocks/js/dist/content-blocks/content-blocks.esm.js"></script>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
| Slot | What 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.
| Attribute | Type | Default | Description |
|---|---|---|---|
altresponsive | String | – | Not documented yet |
aspect-ratioresponsive | String | – | Not documented yet |
classesresponsive | String | – | 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-priority | Select | – | How soon the browser should download the image compared with other files. Use "high" for the main image of the page. |
heightresponsive | Number | '9' | Not documented yet |
lazy-load | Boolean | true | Images 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. |
paddingresponsive | String | – | 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-contentresponsive | Boolean | 'false|true' | If true, the content in the mediaContent slot will be visible. |
srcresponsive | Media | – | Not documented yet |
type | Select | 'image' | Not documented yet |
video-type | Select | 'video/mp4' | Not documented yet |
widthresponsive | Number | '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
