Use up and down keys to navigate results once you've typed more than two characters. Use the enter key to select a result. Touch device users, explore by touch or with swipe gestures.
Image
Overview
Adds an image to the page with an optional caption.
Improved approach for retina screens
Uses two versions of the image, one for standard screens and the other for retina screens.
We specify a folder path for both small and large images which is defined in the macro as smallSrc and largeSrc. The filename is expected to be the same for both.
If the image is decorative and does not convey important information, do not add an alt tag. This will then be hidden from screen reader users.
{% from "components/image/_macro.njk" import onsImage %}
{{
onsImage({
"src": '/img/small/woman-in-purple-dress-shirt.jpg',
"alt": 'Woman in a purple dress shirt using a laptop',
"caption": 'Image 1 - Woman in a purple dress shirt using a laptop'
})
}}
Nunjucks macro options
Name
Type
Required
Description
src
string
true (unless image is set)
The complete source path of the image including filename and extension
image
Object<Image>
true (unless url is set)
Settings for the path and filename attributes for the image
alt
string
false
The HTML alt tag used to explain the appearance and function of the image. Not required if the image is only decorative.
caption
string
false
A short visible caption describing the contents of the image
Image
Name
Type
Required
Description
smallSrc
string
true
Path to the small version of the image
largeSrc
string
false
Path to the large retina version of the image
HTML
<figure class="ons-image">
<img class="ons-image__img" src="/img/small/woman-in-purple-dress-shirt.jpg"
alt="Woman in a purple dress shirt using a laptop" />
<figcaption class="ons-image__caption">Image 1 - Woman in a purple dress shirt using a laptop</figcaption>
</figure>