Overview
An image is a box with one img inside. The box has a set shape, and the photo fills it: the parts that do not fit are cut off. Or the box takes the photo’s own shape, and nothing is cut. A focal point picks the part of the photo that stays in view, and an overlay dims the photo with the overlay color.
Pick another component when:
Markup
Variants
Ratio, Focal point, Overlay and Radius set a custom property in the style attribute of .nds-image. Any other value works too: see API.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Photo (default) | — | — | One photo in a set shape |
| Structure | Viewer thumbnail | canon #image-viewer |
— | A gallery tile of the Image Popup Viewer: a click opens the full photo. The outer div is one grid cell: the tile and its title. Keep nds-ipv-thumbnail on the img and nds-image on its card |
| Structure | With caption | canon #image-figure |
— | A photo with a caption under it. nds-image goes on a box inside the figure: on the figure itself, it cuts off the caption |
| Ratio | 4:3 (default) | — | — | Gallery tiles and list thumbnails |
| Ratio | 16:9 | --image-ratio: 16 / 9 |
.nds-image |
Wide photos and video stills |
| Ratio | 2:1 | --image-ratio: 2 / 1 |
.nds-image |
Banners. The same shape as a card’s image header |
| Ratio | 1:1 | --image-ratio: 1 |
.nds-image |
Square tiles |
| Ratio | 3:4 | --image-ratio: 3 / 4 |
.nds-image |
Upright photos, such as a building or a full-length portrait |
| Ratio | 3:1 | --image-ratio: 3 / 1 |
.nds-image |
A thin strip, such as a banner across a page section |
| Ratio | Original (limit: 1 crop) | --image-ratio: auto |
.nds-image |
The photo keeps its own shape and nothing is cut, so the focal point does nothing. Give the img a width and height |
| Focal point | Center (default) | — | — | The middle of the photo stays in view |
| Focal point | Left (limit: 1 crop) | --image-pos-x: 0% |
.nds-image |
The left side stays in view, in both text directions. For a photo wider than its shape |
| Focal point | Right (limit: 1 crop) | --image-pos-x: 100% |
.nds-image |
The right side stays in view, in both text directions |
| Focal point | Top (limit: 1 crop) | --image-pos-y: 0% |
.nds-image |
The top stays in view: a face, a skyline. For a photo taller than its shape |
| Focal point | Bottom (limit: 1 crop) | --image-pos-y: 100% |
.nds-image |
The bottom stays in view |
| Overlay | None (default) | — | — | The photo as it is |
| Overlay | Light | --image-overlay-opacity: 0.3 |
.nds-image |
A photo that steps back, such as a past event |
| Overlay | Strong | --image-overlay-opacity: 0.6 |
.nds-image |
A photo kept only as a texture |
| Radius | MD (default) | — | — | 8px rounded corners, as a card’s image |
| Radius | LG | --image-radius: var(--radius-lg) |
.nds-image |
16px rounded corners, for a large photo |
| Radius | None | --image-radius: 0 |
.nds-image |
Square corners, for a photo that meets the edge of its container |
Built-in Features
-
CSS Only
An image needs no script and no init call. Every option is a custom property.
-
Crop to Fill
The photo covers the whole box at any size, and the box keeps its ratio. A row of photos of different sizes lines up.
-
Focal Point
--image-pos-xand--image-pos-ypick the part of the photo that stays in view when the ratio cuts it. -
Custom Ratio
--image-ratiotakes any width / height, such as5 / 2, not only the ratios in the builder.autokeeps the photo's own shape.
Best Practices
- Put one
imgin the box. The rules style one image only. - For a caption, put the image box and a
figcaptionin afigure. Never putnds-imageon thefigure: the box cuts off the caption. - Put a row of images in a Grid, all with the same ratio, so the row stays even. Each image fills the width of its column.
- Write
alton theimg. Writealt=""when a caption or the text next to the image says the same. - Set the focal point when the subject is not in the middle. Without it, the ratio can cut off a face at the top.
- Keep the overlay at 0.6 or less. A stronger overlay hides the photo.
- Set the radius to 0 when the photo meets the edge of its container.
- Set the knobs in the
styleattribute or in your CSS, not with a new class. - For a gallery the user opens full screen, use the Viewer thumbnail structure. Leave
nds-imageoff when the gallery needs your own look:nds-ipv-thumbnailadds no style. - Add
loading="lazy"to an image far down the page. The box holds its ratio before the photo loads, so the page does not jump. - With
--image-ratio: auto, give theimgawidthandheight. The box then holds its space before the photo loads. - Inside Prose, a plain
imgalready has rounded corners. Use Image there for a ratio or an overlay.
API
CSS Custom Properties
Set these on .nds-image, or on a parent to change every image inside it. A card’s .nds-card-image reads the same properties. A hero has its own: see Hero.
| Property | Default | Controls |
|---|---|---|
--image-ratio |
4 / 3 |
The shape of the box, as width / height. auto keeps the photo’s own shape. A card’s image header defaults to 2 / 1 |
--image-pos-x |
50% |
The part of the photo in view across. 0% is the left edge in both text directions |
--image-pos-y |
50% |
The part of the photo in view down. 0% is the top edge |
--image-radius |
var(--radius-md) |
The corner radius of the box |
--image-overlay-opacity |
0 |
How much the overlay covers the photo, from 0 to 1 |
--image-overlay-color |
var(--background-image-overlay) |
The overlay color |