Skip to main content
Login

Sign in to access your account

Image - National Design System

A photo cropped to fill a set shape, with a focal point and an optional overlay

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:

  • the photo sits at the top of a card: the image header of a Card, with the same knobs
  • the photo shows a person: Avatar
  • the photo fills the top of a page: Hero

Markup

Options
Structure
Ratio
Focal point
Overlay
Radius
Preview
A man in traditional dress outside an old stone house
<div class="nds-image"> <img src="../docs-assets/events/foundation_day/Hero_bg.webp" alt="A man in traditional dress outside an old stone house"> </div>

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-x and --image-pos-y pick the part of the photo that stays in view when the ratio cuts it.

  • Custom Ratio

    --image-ratio takes any width / height, such as 5 / 2, not only the ratios in the builder. auto keeps the photo's own shape.

Best Practices

  • Put one img in the box. The rules style one image only.
  • For a caption, put the image box and a figcaption in a figure. Never put nds-image on the figure: 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 alt on the img. Write alt="" 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 style attribute or in your CSS, not with a new class.
  • For a gallery the user opens full screen, use the Viewer thumbnail structure. Leave nds-image off when the gallery needs your own look: nds-ipv-thumbnail adds 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 the img a width and height. The box then holds its space before the photo loads.
  • Inside Prose, a plain img already 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
Last Modified Date: 25/10/2026 - 09:51 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks