Overview
The top bar is the first bar of every page. On the start side, the Digital Stamp tab tells people the site is a registered government website. On the end side, up to two items show today’s date, the time or the weather, next to the dark mode button.
A toggle in the bar opens an expander: a strip that slides open below the bar. The stamp is one expander, and a site can add its own.
The top bar is a page shell part. The preview shows it in a frame of its own, so it does not clash with this page’s own top bar.
The main navigation belongs in the Header, and the links at the end of the page in the Footer.
Markup
Parts
| Part | Holds | Required |
|---|---|---|
.nds-topbar |
The whole bar. Add nds-content-wrapper to keep its content at the page width |
Yes |
button.nds-digital-stamp-tab |
The stamp’s toggle, first in the bar. Its parts are listed on Digital Stamp | Yes, on a government site |
.nds-topbar-info |
The items and the buttons, on the end side. Never put it on the stamp tab: its wide gap stretches the tab’s contents apart | No |
span.nds-meta |
One item: Today, the clock or the weather, in a Meta line. The bar shows it at Meta’s LG size; nds-md or nds-sm on the span picks a smaller one |
No |
button[data-theme-toggle] |
The dark mode button | No |
button[data-topbar-toggle] |
A toggle: aria-controls names its expander’s id. The stamp tab is one |
No |
.nds-topbar-expander |
A strip right after the bar, hidden until its toggle opens it. It holds a .nds-content-wrapper, which keeps the content at the page width. #nds-digital-stamp is one |
Yes, with each toggle |
.nds-topbar-expander-content |
The content, inside the .nds-content-wrapper, with space above and below it. Never put the space on the wrapper: the slide would stop short of closed |
Yes |
Variants
Each part of the bar is one row of chips. Show adds or removes the part, and the parts always keep the table order. The Expanders row adds or removes each expander with its toggle. The canon carries the stamp, Today, the clock and the dark mode button.
DGA allows two items at most. Today, the clock and the weather share (limit: 2 items), so with two on, the third stays off. Hide on adds its token to the item’s data-hidden.
Each expander changes two places, so write both of its rows. Digital stamp adds its tab at the start of .nds-topbar and its expander right after the bar. More adds its toggle at the start of .nds-topbar-info and its expander right after the bar.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Expanders (any) | Digital stamp (default) | canon #topbar-stamp-tab |
.nds-topbar (start) |
The stamp tab and the stamp. A government site must show them. Turn it off only for a site that DGA has not registered. See Digital Stamp |
| Expanders (any) | Digital stamp (default) | canon #topbar-stamp-panel |
.nds-topbar (after) |
|
| Expanders (any) | More (hint: A second strip that slides open below the bar) | canon #topbar-more-toggle |
.nds-topbar-info (start) |
A toggle and its expander. Replace the placeholder with your content, such as a notice with its links or a set of services |
| Expanders (any) | More (hint: A second strip that slides open below the bar) | canon #topbar-more-strip |
.nds-topbar (after) |
|
| Today (any) | Show (default) (limit: 2 items) | canon #topbar-today |
.nds-topbar-info |
Today’s date. Pair it with the clock for a time-bound service: appointments, deadlines, submissions |
| Today (any) | Hide on phone (default) (hint: Below 600px) | [data-hidden~="sm"] |
.nds-meta:has(time[data-date-today]) |
Hides the date below 600px |
| Today (any) | Hide on tablet (default) (hint: 600px to 959px) | [data-hidden~="md"] |
.nds-meta:has(time[data-date-today]) |
Hides the date from 600px to 959px |
| Today (any) | Gregorian | [data-calendar="gregory"] |
time[data-date-today] |
Replaces hijri: the month’s name, with no weekday. Pick it for an English service for international visitors. The Hijri date suits Arabic pages and Saudi government sites |
| Clock (any) | Show (default) (limit: 2 items) | canon #topbar-clock |
.nds-topbar-info |
The time. Leave it out when the date shows elsewhere on the page |
| Clock (any) | Hide on phone (default) (hint: Below 600px) | [data-hidden~="sm"] |
.nds-meta:has(.nds-clock) |
Hides the clock below 600px |
| Clock (any) | Hide on tablet (hint: 600px to 959px) | [data-hidden~="md"] |
.nds-meta:has(.nds-clock) |
Hides the clock from 600px to 959px |
| Weather (any) | Show (limit: 2 items) | canon #topbar-weather |
.nds-topbar-info |
The place and its weather. Pick it for a portal where people want general awareness: citizen services, public dashboards |
| Weather (any) | Hide on phone (default) (hint: Below 600px) | [data-hidden~="sm"] |
.nds-meta:has(.nds-weather) |
Hides the weather below 600px |
| Weather (any) | Hide on tablet (hint: 600px to 959px) | [data-hidden~="md"] |
.nds-meta:has(.nds-weather) |
Hides the weather from 600px to 959px |
| Theme button (any) | Show (default) (hint: The dark mode button in the bar) | canon #topbar-dark |
.nds-topbar-info |
The dark mode button, last in the row |
Behavior
Expanders
A toggle opens its expander, which slides open below the bar and pushes the page down. A second press, Escape, or a click outside closes it. An Escape that closes a Modal leaves it open. When it closes with the keyboard focus inside, the focus moves to its toggle. Only one expander is open at a time. If a visitor opens another, the open one slides closed first. If a visitor presses several toggles meanwhile, the last one opens.
A click that opens the main navigation closes an open expander, and a click on a toggle closes the navigation.
Digital Stamp
The stamp is an expander: its tab is the toggle, and #nds-digital-stamp is the expander. Its text, its address card and its markup are on Digital Stamp.
Items
Today is on Date, the clock on Clock, and the weather on Weather. Each one is a Meta item that the script fills, so it works outside the bar too, where a page can show any number of them.
Items on Small Screens
data-hidden on an item hides it inside the named width bands: sm below 600px (phones), md from 600px to 959px (tablets), lg from 960px. Combine tokens to hide across bands. Today and the clock write no text while data-hidden hides them. See Date, Clock and Hidden.
Built-in Features
-
Auto Start
The loader starts the top bar's script when the page has a toggle. One click listener on the document serves every toggle and expander, including ones added later.
-
Push-Down Expanders
An expander takes its place in the page under the bar, so it covers nothing. The slide turns off when the visitor's system asks for reduced motion.
Best Practices
- Show two items at most: two of Today, the clock and the weather. DGA allows no more. The dark mode button and the toggles are not items.
- Put
data-hiddenon every item, so the bar stays readable on a phone:"sm md"on Today,"sm"on the clock and the weather. An item without it shows at every width and crowds the stamp tab. - Use an expander for content that needs the page’s width and belongs to the whole site, such as a notice with its links or a set of services. Site navigation belongs in the Main Navigation.
- Put small content in a Dropmenu or a Tooltip, not an expander. A short line in a full-width expander pushes the whole page down.
- Write
aria-expanded="false"on each toggle andhiddenon each expander. The page then reads right before the script loads. - Give each expander
role="region"and anaria-labelthat names its content.
API
Data Attributes
| Attribute | Element | Effect |
|---|---|---|
data-topbar-toggle |
A button in the bar | Written bare. Makes it a toggle for the expander that its aria-controls names |
aria-controls |
A toggle | The id of its expander |
aria-expanded |
A toggle | Write false in the markup. The script sets true when its expander opens, and false when it closes |
data-state="expanded" |
A toggle | The script sets it when its expander opens, and removes it when the expander closes |
hidden |
.nds-topbar-expander |
Write it in the markup. The script removes it when the expander opens, and sets it again after the expander closes |
data-state |
.nds-topbar-expander |
The script sets open and opening when the expander opens. It adds closing when the expander closes. It removes all three after the close |
data-hidden |
An item’s span.nds-meta |
Hides it in the named width bands: sm, md, lg, space-separated. See Hidden |
data-theme-toggle |
A button | Makes it the dark mode button. See Themes |
CSS Custom Properties
| Property | Default | Controls |
|---|---|---|
--background-topbar |
Theme token | The background of the bar and of every expander |
--topbar-expander-padding |
var(--spacing-2xl), var(--spacing-5xl) in the stamp |
The space above and below .nds-topbar-expander-content. Set it on the expander or on the content |
JavaScript
NDS.Topbar loads after the page shows. Until it loads, a call to it loads it and returns a promise of the result, so await a call whose result you use. Each method takes an expander, as an id or as the expander element.
| Method | Effect |
|---|---|
NDS.Topbar.open(expander) |
Opens it. An open expander slides closed first |
NDS.Topbar.close(expander) |
Closes it |
NDS.Topbar.toggle(expander) |
Opens or closes it |
NDS.Topbar.isOpen(expander) |
Returns true while it is open and not closing |
NDS.Topbar.init() |
Starts the toggles, Escape and the outside click, once per page. The loader runs it |
| Event | Fired on | Detail |
|---|---|---|
nds:topbar:opened |
The expander. It bubbles | { expander }. Fires when it starts to open |
nds:topbar:closed |
The expander. It bubbles | { expander }. Fires after it has closed |
The full API is in the banner of _js/nds-topbar.js.