{% include '@bolt-elements-image/image.twig' with {
fill: true,
attributes: {
alt: 'Image alt text',
src: 'path/image.jpg',
width: 500,
height: 500,
},
} only %}
Prop Name | Description | Type | Default Value | Option(s) |
---|---|---|---|---|
attributes
|
A Drupal-style attributes object with extra attributes to append to this element. |
object
| — |
|
fill
|
Render the image 100% wide, filling up the full width of its parent container. |
boolean
| — |
|
background
|
Render the image as a background image. This sets the image to be absolute positioned, only use this prop if the image is inside a non-static container. |
boolean
| — |
|
npm install @bolt/elements-image
{% include '@bolt-elements-image/image.twig' with {
attributes: {
alt: 'Alt text.',
src: 'path/image.jpg',
width: 400,
height: 225,
},
} only %}
<img alt="Alt text." src="path/image.jpg" width=400 height=225 class="e-bolt-image">
srcset
and sizes
attributes to render various resolutions of the same image at specific breakpoints.
{% include '@bolt-elements-image/image.twig' with {
attributes: {
alt: 'Alt text.',
src: 'path/image-800.jpg',
srcset: 'path/image-400.jpg 400w, path/image-800.jpg 800w',
sizes: '50vw',
width: 800,
height: 450,
},
} only %}
<img alt="Alt text." src="path/image-800.jpg" srcset="path/image-400.jpg 400w, path/image-800.jpg 800w" sizes="50vw" width=800 height=450 class="e-bolt-image">
fill
prop will stretch the image to fill up 100% width of its parent container, ignoring the image’s true width and height.
{% include '@bolt-elements-image/image.twig' with {
fill: true,
attributes: {
alt: 'Alt text.',
src: 'path/image-800.jpg',
srcset: 'path/image-400.jpg 400w, path/image-800.jpg 800w',
sizes: '96vw',
width: 800,
height: 450,
},
} only %}
<img alt="Alt text." src="path/image-800.jpg" srcset="path/image-400.jpg 400w, path/image-800.jpg 800w" sizes="96vw" width=800 height=450 class="e-bolt-image e-bolt-image--fill">
background
prop will transform the image into a background image.
<div style="position:relative;">
// This image will fill up the non-static parent container
{% include '@bolt-elements-image/image.twig' with {
background: true,
attributes: {
src: 'path/image-1600.jpg',
srcset: 'path/image-400.jpg 400w, path/image-800.jpg 800w, path/image-1600.jpg 1600w',
sizes: '100vw',
width: 1600,
height: 900,
},
} only %}
<div style="position:relative;">
// Content goes here after the image
</div>
</div>
<div style="position:relative;">
// This image will fill up the non-static parent container
<img src="path/image-1600.jpg" srcset="path/image-400.jpg 400w, path/image-800.jpg 800w, path/image-1600.jpg 1600w" sizes="100vw" width=1600 height=900 class="e-bolt-image e-bolt-image--bg" alt="">
<div style="position:relative;">
// Content goes here after the image
</div>
</div>
background
prop, there are 2 CSS custom properties available for use to further customize background image(s). They are commonly used when multiple decorative background images are required.
<div style="position:relative;">
// This background image will not be cropped and it is positioned to center of the non-static parent container.
{% include '@bolt-elements-image/image.twig' with {
background: true,
attributes: {
src: 'path/image.jpg',
width: 500,
height: 500,
style: '--e-bolt-image-fit: contain; --e-bolt-image-position: center center;',
},
} only %}
// This background image will not stretch and it is positioned to top left of the non-static parent container.
{% include '@bolt-elements-image/image.twig' with {
background: true,
attributes: {
src: 'path/image.jpg',
width: 150,
height: 150,
style: '--e-bolt-image-fit: none; --e-bolt-image-position: top left;',
},
} only %}
</div>
<div style="position:relative;">
// This background image will not be cropped and it is positioned to center of the non-static parent container.
<img src="path/image.jpg" width=500 height=500 style="--e-bolt-image-fit: contain; --e-bolt-image-position: center center;" class="e-bolt-image e-bolt-image--bg" alt="">
// This background image will not stretch and it is positioned to top left of the non-static parent container.
<img src="path/image.jpg" width=150 height=150 style="--e-bolt-image-fit: none; --e-bolt-image-position: top left;" class="e-bolt-image e-bolt-image--bg" alt="">
</div>
<picture>
HTML element can help with art directing a particular graphical area of a page.
Completely different images are loaded via the <picture>
HTML element, resize this page to see the image on the left change.
<picture>
// Set the image sources
<source srcset="path/image-2x.jpg 2x, path/image.jpg" media="(min-width: 1000px)">
<source srcset="path/image-b-1200.jpg 2x, path/image-b-600.jpg" media="(min-width: 600px)">
<source srcset="path/image-a-600.jpg 2x, path/image-a-300.jpg" media="(min-width: 300px)">
// Set the fallback image
{% include '@bolt-elements-image/image.twig' with {
attributes: {
alt: 'Alt text.',
src: 'path/image.jpg',
srcset: 'path/image-2x.jpg 2x',
width: 1000,
height: 500,
},
} only %}
</picture>
<picture>
// Set the image sources
<source srcset="path/image-2x.jpg 2x, path/image.jpg" media="(min-width: 1000px)">
<source srcset="path/image-b-1200.jpg 2x, path/image-b-600.jpg" media="(min-width: 600px)">
<source srcset="path/image-a-600.jpg 2x, path/image-a-300.jpg" media="(min-width: 300px)">
// Set the fallback image
<img src="path/image.jpg" srcset="path/image-2x.jpg 2x" width=1000 height=500 class="e-bolt-image" alt="Alt text.">
</picture>