Overview
The hero is the first section in main. It comes in two forms. The sub hero is on most pages: a breadcrumb, the page title and a description, on a light tint of the brand primary. A service page and a profile page have their own shape of it. The main hero is on the home page: a Swiper of slides, each with a full-width image under a tint and its own title.
Pick another component when:
- the title belongs to a section of the content, not to the page: Section
- the page says that something was not found, sent or failed: Status Section
- the slides are cards or images inside the content: Swiper
The hero is one region of the page. The other regions are on Page Layout.
Markup
Parts
The sub hero is a section with a breadcrumb before its wrapper. Its head parts are the parts of a Section head, in this order: the title action, the title, the brief, the tags, then the description.
| Part | Holds | Required |
|---|---|---|
section.nds-hero-section.nds-sub |
The sub hero | Yes |
nav.nds-breadcrumb-nav |
The Breadcrumb. The last item is the page, with nds-truncate and aria-current="page" |
Yes |
.nds-section-wrapper |
The head, and the action row after it | Yes |
.nds-section-image |
A 120px Avatar before the head (80px on phones). For a page about one person or entity | No |
.nds-section-head |
The head parts, in the order above | Yes |
.nds-section-action in the head |
The title action: written first in the head, it floats on the end side of the title. With data-hidden="sm sr" on their labels, its buttons show only their icons on phones, so each one needs an icon. With nds-wrap, it moves under the title on phones |
No |
h1.nds-section-title |
The page title. The sub hero holds the page’s h1 |
Yes |
.nds-section-brief |
One short line under the title, in semibold | No |
.nds-section-meta |
Under the title: a .nds-section-tags of small Tags, a Meta line such as an article’s dates and author, or both |
No |
.nds-section-description |
One or two sentences on the page | Yes |
.nds-section-action after the head |
The action row. It sits beside the head, on the end side, and moves under the description when the head has a title action | No |
The main hero is a section that holds one hero swiper. The navigation row is the Swiper’s.
| Part | Holds | Required |
|---|---|---|
section.nds-hero-section |
The main hero, with no nds-sub |
Yes |
.nds-swiper.nds-hero |
The slides. Write nds-oncolor and nds-full-width with it |
Yes |
.nds-swiper-slide.nds-content-wrapper |
One slide. Write hidden on every slide after the first |
Yes |
.nds-hero-image-wrapper |
The image and its tint. --hero-overlay-opacity in its style sets the tint for the slide, and --hero-image-position the part of the image in view |
Yes |
img.nds-hero-image |
The image, in a picture with one source for each screen size. Give it alt="": the image is decoration |
Yes |
.nds-section-body |
The title, the description and a .nds-section-action with one or two buttons. The first slide’s title is the page’s h1, the others are h2 |
Yes |
Variants
The structures are the shapes the site uses. For another mix of the head parts, see Parts. Background is for Sub hero and Service. The slider options of the main hero, such as Loop and the arrows at the middle, are on Swiper. nds-aside is in the API: it works only with a side info column.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Structure | Sub hero (default) | — | — | The top of most pages: the breadcrumb, Share beside the title, the title and a description |
| Structure | Service (hint: A service page: a main button, Share and tags) | canon #hero-service |
— | A service page: a main button and Share beside the title, and tags under it. Write nds-aside too when the page has a side info column |
| Structure | Profile (id: profile) (hint: A page about one person, with an avatar) | canon #hero-profile |
— | A page about one person or entity: a flat hero with an Avatar before the name, and Share beside the head |
| Structure | Main hero (hint: The home page slider of full-width images) | canon #hero-main |
— | The home page: a slider of full-width images, each with a title and a button |
| Second action | Second action (hint: An outline button beside each slide’s button) | canon #hero-main-action |
.nds-hero .nds-section-action |
A second, lesser action on a slide, after its main button. Write it as nds-secondary-outline nds-oncolor nds-lg |
| Background | Tint (default) (not: profile) (hint: A light brand tint with an inner shadow) | — | .nds-hero-section.nds-sub |
A light tint of the brand primary, with a shadow inside its edges |
| Background | Image (not: profile) | --hero-image: url('../assets/img/riyadhcenter_ai.webp') |
.nds-hero-section.nds-sub |
A photo on the end side, which fades into the tint toward the title. For a page with its own photo |
| Background | Flat (not: profile) (hint: The page background, with no tint, shadow or image) | .nds-flat |
.nds-hero-section.nds-sub |
The page background, with no tint, shadow or image. For an article or a form, where the content starts right under the title |
| No share | No share (hint: A page with no Share menu) | remove |
.nds-section-action:not(.nds-wrap):has(> .nds-share) |
Leave out Share, for a page with no public link, such as a console. Where Share is alone in its .nds-section-action, remove that element too |
| No share | No share (hint: A page with no Share menu) | remove |
.nds-share |
Leave out Share, for a page with no public link, such as a console. Where Share is alone in its .nds-section-action, remove that element too |
Behavior
Hero Slider
The main hero shows one slide at a time, and the Swiper script moves between them. Before the script starts, only the first slide shows, so the page paints with its image. The later slides load their images from data-src and data-srcset when they come near the screen. The slider options are on Swiper.
Background Image
--hero-image on the sub hero puts a photo behind it. The photo is solid at the end side and fades out toward the title, so the tint shows under the text. The fade turns with the text direction. The tint also covers half of the photo. Knobs in the API change the fade, the part in view and the tint. nds-flat hides the photo.
Built-in Features
-
First Paint
The title, the description and the breadcrumb paint with the critical CSS, before the rest of the page. The buttons keep their height while they load, so nothing moves.
-
Height
The main hero is 550px high on every screen, and each image covers it.
--hero-heightchanges it. The sub hero is as high as its content, at least 220px. -
Title Sizes
The main hero's title is a large display size, and the sub hero's is one size smaller. Both scale with the screen width.
-
Brand Tint
The tint over a slide image and the sub hero background come from theme tokens, so they follow a brand change.
Best Practices
- Use the main hero on the home page and on the home page of a sub-site. Every other page uses the sub hero.
- Keep the description to one or two sentences. The hero says where the reader is. The content comes after it.
- Put one or two buttons in the action row. In the title action, put Share and at most one main button, such as the start of a service. Share is optional: leave it out on a page with no public link, such as a console.
- Give the first slide’s image
fetchpriority="high". It is the largest paint on the home page. - Preload the first slide’s image in the
<head>, with one<link rel="preload" as="image">for eachsource. Copy themediaof eachsourceexactly, or the browser loads one file and paints another. Each page preloads only its own hero image. See Head. - Give each later slide’s
imgadata-src, and each of itssourceelements adata-srcset. A plainsrcsetloads at once. - Keep a photo in the main hero. If the photo is not ready, point the
pictureat a placeholder image and replace it later. - Set
--hero-overlay-opacityon each slide for its image: about 0.4 to 0.5 for a dark image, and 0.6 to 0.8 for a bright one. - Do not set
--background-image-overlay. It follows the brand, and a fixed value stops that. - For a photo in the sub hero, pick one with its subject on one side. The fade keeps the end side and hides the side of the title.
- Do not write
nds-oncoloron text in a flat hero: it shows white on a light page.
API
Other Classes
| Class | Element | Effect |
|---|---|---|
nds-aside |
section.nds-hero-section.nds-sub |
At 960px and wider, narrows the breadcrumb, the title and the description by the width of the side info column. The column then moves up beside the title. Write it only on a page with a side info column: see Side Info |
CSS Custom Properties
| Property | Default | Controls |
|---|---|---|
--hero-height |
550px |
The height of the main hero. Set it in the style of the section |
--hero-image |
None | The photo of the sub hero, as url('…'). Set it in the style of the section |
--hero-image-position |
50% 50% on a slide, left center on the sub hero |
The part of the image that stays in view, such as 50% 30%. On the main hero, set it in the style of each .nds-hero-image-wrapper. On the sub hero, set it in the style of the section, with --hero-image |
--hero-image-fade-angle |
90deg, or 270deg on a left-to-right page |
The direction of the photo’s fade. Another angle fades it from the top or a corner |
--hero-image-fade-from |
0% |
Where the fade starts. Up to this point, the photo is solid |
--hero-image-fade-to |
70% |
Where the photo is gone |
--hero-overlay-opacity |
0.7 on a slide, 0.5 on the sub hero |
The strength of the tint over the image, from 0 (none) to 1 (solid). On the main hero, set it in the style of each .nds-hero-image-wrapper. On the sub hero, set it in the style of the section, with --hero-image |
--hero-overlay-color |
var(--background-image-overlay) |
The color of the tint on a main hero slide, for one slide that needs another color. On the sub hero, the tint is the section’s own background |
--background-image-overlay |
var(--colors-primary-950) |
The default tint color, a theme token. A custom brand sets it to var(--colors-neutral-950). Do not set it |
--background-hero |
var(--background-primary-strong) |
The color behind the main hero, a theme token. It shows until the first image loads |
--background-sub-hero |
var(--background-primary-light) |
The color of the sub hero, a theme token. High contrast mode changes it |
JavaScript
The hero has no script of its own. The Swiper script runs the main hero, and the Share script runs the Share menu: see Swiper and Share.