Skip to main content
Login

Sign in to access your account

Panels - National Design System

A panel is a surface that slides in from an edge of the screen, for settings, filters or details the user opens on demand.

Overview

A panel is a <dialog class="nds-panel"> and a button with data-panel-toggle that opens it. The panel holds three optional parts: a header (nds-panel-header), a body (nds-panel-body) and a footer (nds-panel-footer). The panel does not style the content you put in the body.

Pick another component when:

  • the user must answer a short question before going on: Modal
  • the content is a list of navigation links: Drawer or Side Menu
  • the menu holds a few actions beside its button: Dropmenu
  • the content switches in place on the page: Tabs

Markup

Options
Structure
Side
Size
More
Preview
Settings

Adjust how this page behaves.

Swap with content component استبدل هذا العنصر بأي عنصر آخر
<button type="button" class="nds-btn nds-primary nds-lg" data-panel-toggle="settings-panel"> <span class="nds-label">Open Panel</span> </button> <dialog id="settings-panel" class="nds-panel" aria-label="Settings"> <div class="nds-panel-header"> <span class="nds-featured-icon nds-circle"> <i class="hgi hgi-stroke hgi-settings-01"></i> </span> <div class="nds-panel-text"> <span class="nds-panel-title">Settings</span> <p class="nds-panel-description">Adjust how this page behaves.</p> </div> <div class="nds-panel-action"> <button type="button" class="nds-btn nds-subtle nds-icon-only" data-panel-close aria-label="Close panel" data-i18n-aria-label="panel.close_panel"> <i class="nds-icon nds-hgi-cancel-01" aria-hidden="true"></i> </button> </div> </div> <div class="nds-panel-body"> <div class="nds-content-placeholder"> <span>Swap with content component</span> <span>استبدل هذا العنصر بأي عنصر آخر</span> </div> </div> <div class="nds-panel-footer"> <button type="button" class="nds-btn nds-primary nds-full" data-panel-close> <span class="nds-label">Done</span> </button> </div> </dialog>

Behavior

Side

data-panel-side picks the edge the panel slides in from. Start and end follow the reading direction, so an end panel opens on the left in Arabic and on the right in English. Left and right stay on the same edge in every language. A side panel is 420px wide, or the full width of a smaller screen.

Sheet

A top or bottom panel is a sheet: it spans the full width of the screen. The sheet is as tall as its content, up to 60% of the screen, and the body scrolls past that. Its content lines up with the page content at every screen size. Only the two corners that face the page are rounded.

A panel without data-panel-modal leaves the page usable, so the user can see a filter or a setting change the page. data-panel-modal is for a panel the user must finish first, such as a checkout step. It dims the page behind the panel and stops it from scrolling. Tab and Shift + Tab then stay inside the panel, and a click on the dimmed page closes it.

Static

data-panel-static turns off the two ways a user closes a panel by accident: Escape and a click outside it. The panel closes only from a data-panel-close control or a script. Another panel can still take its place, as Stacking shows.

Stacking

Each kind of panel has its own rule when another panel opens:

  • A plain panel replaces an open plain panel. It waits until the old one slides out, so the two never cross.
  • A modal panel closes nothing. Its dimmed layer covers the panels under it.
  • A panel the user opens over a modal, or over a modal panel, opens as a modal panel too. It covers the one under it, and plain and static panels do not close it.
  • A static panel that the page opens with { focus: false } waits until no panel is open. A static panel that a toggle or a script opens shows at once, like a plain panel.
  • When another panel replaces a static panel, the static panel hides. It comes back when the screen has no open panel again.

Only the top panel closes on Escape or a click outside, and only the top modal panel keeps focus. A Modal sits above every panel. While it is open, no panel closes on Escape or a click, and no panel keeps focus.

Resize

A button with data-panel-resize="grow" or "shrink" moves the panel one step along four sizes: sm, md (the default), lg and xl. A side panel changes its width. A sheet changes its height, and a resizable sheet keeps that height even when its content is shorter. The panel never grows past the screen: the plus button gets aria-disabled="true" at the largest size, or sooner when the panel already fills the screen. The minus button gets it at the smallest size. Put the buttons in one nds-btn-group inside nds-panel-action, with the close button last. Put data-panel-size on the panel to start at another size. A --panel-width or --panel-height you set is the md size, and the other sizes scale from it: sm is three quarters of it, lg a third larger and xl three quarters larger.

Lazy Panel

A lazy panel keeps its markup in a <template class="nds-panel-template">, so it adds nothing to the page until the first click. The toggle stays outside the template. On that click, the panel joins the page, and NDS starts the components inside it. Put one panel in each template.

Built-in Features

  • Auto-initialization

    Every .nds-panel on the page starts by itself. The toggle and close buttons work from their attributes, with no script of your own.

  • Focus Management

    Focus moves to the first close button when the panel opens, or to the panel when it has none, and back when it closes: to the toggle, or to what had focus when a script opened it. A panel destroyed while open, as a framework unmount or React's StrictMode does, sends it back too. Escape and a click outside close the top panel.

  • Panel Stacking

    A plain panel replaces the open one after it slides out. A modal panel covers the others and the main navigation, and a static panel comes back when the screen is clear. A panel you open from a modal opens over it.

  • Header-Aware Position

    The panel starts below the sticky header, and moves with it as the top bar scrolls in and out. A tall sheet stops at the header. A modal panel covers the header and starts at the top of the screen.

  • Programmatic Control

    Open, close and toggle a panel from a script, check whether it is open, and listen to its events.

Best Practices

  • Use a panel for content that supports the main task without replacing it: settings, filters, the details of an item, a short form.
  • Give every panel an id, and give its toggle that id in data-panel-toggle. A panel without an id cannot be opened.
  • Give the panel an aria-label that names it, and each icon-only button an aria-label.
  • Make the panel a <dialog>, with no hidden attribute. A closed dialog stays hidden before the script loads. Any other element does not open.
  • Give every button type="button". In a form, a button without it submits the form.
  • Prefer the start and end sides, so the panel follows the reading direction. Use left or right only when the panel must stay on one edge in every language.
  • Use a bottom sheet for actions on a phone, and a side panel for settings or filters on a large screen.
  • Keep the title in nds-panel-text in the header, with an optional nds-panel-description below it. A Modal with a form or a list puts its title in the header the same way.
  • Do not look up a lazy panel when the page loads: it is not in the page yet. Listen on document for nds:template:ready, which fires on the panel after it joins the page and its components start.

API

Classes

Class Element Effect
nds-panel the panel <dialog> The sliding surface
nds-panel-header div in .nds-panel The top row: an optional featured icon, the text and the header buttons, with a divider below
nds-panel-text div in .nds-panel-header Holds the title and the description, and fills the free space in the row. A bare nds-panel-title also fills it
nds-panel-title span in .nds-panel-text The panel’s title
nds-panel-description p in .nds-panel-text A short line below the title
nds-panel-action div in .nds-panel-header Holds the header buttons: the close button, and any beside it, such as a Reset button or the resize group. They sit closer together than the header items
nds-panel-body div in .nds-panel The content. It scrolls when the content is taller than the panel
nds-panel-footer div in .nds-panel A row of buttons at the bottom, with a divider above. A button that does not fit moves to the next line. It takes the same classes as card actions: nds-end, nds-reverse, nds-col, and nds-col-sm to stack the buttons below 600px
nds-scroll-more div in .nds-panel in place of .nds-panel-body, or on .nds-panel-body itself A Scroll More area fills the same space as the body
nds-panel-template <template> Holds a lazy panel

On a phone, the header buttons shrink to 32px.

Data Attributes

Attribute Element Effect
data-panel-toggle any button on the page Opens or closes the panel whose id is its value. The script sets aria-expanded on it
data-panel-close any element in the panel Closes the panel. The first one gets focus when the panel opens
data-panel-resize a button in the panel grow makes the panel one size larger, shrink one size smaller
data-panel-size .nds-panel The size: sm, md (the default), lg or xl. The script writes it when the user resizes the panel
data-panel-side .nds-panel The edge: end (the default), start, left, right, top or bottom
data-panel-modal .nds-panel Opens the panel as a modal dialog. The page behind it, the main navigation too, is dimmed and does not respond, the page does not scroll, and focus stays in the panel
data-panel-static .nds-panel Escape and a click outside do not close the panel
data-state .nds-panel The script writes open while the panel is open, opening while it slides in and closing while it slides out

CSS Custom Properties

Set these on the .nds-panel element.

Property Default Controls
--panel-width 420px Width of a start, end, left or right panel, at the md size. The panel is never wider than the screen
--panel-height 60svh Most height of a top or bottom sheet, at the md size. The sheet also stops at the header
--panel-content-width var(--nds-content-max-width) Most width of a sheet’s content. 100% spans the full width, inside the page gutter
--panel-top the bottom of the sticky header, 0 on a modal panel Where the panel starts. Any value turns off the header tracking. 0 covers the header too, and needs a --panel-z above the header’s
--panel-padding var(--spacing-lg) Space inside the header, the body and the footer
--panel-gap 0 Space between the header, the body and the footer
--panel-radius 0, var(--radius-lg) on a sheet Corner radius. A sheet rounds only the two corners that face the page
--panel-z 999 Stack order of a plain or static panel. The main navigation is 1000. A modal panel is above everything

Tokens

It reads these shared tokens. A change to one also changes other components: see Tokens.

Source: the var() reads in _sass/components/_panel.scss.

TokenPreviewValue
--background-menu
Read by background-color

var(--colors-base-white)
Dark mode var(--background-default)
--background-overlay
Read by background-color

var(--colors-alpha-black-50)
Dark mode var(--colors-alpha-black-70)
--text-default
Read by color

var(--colors-base-black)
Dark mode var(--colors-neutral-200)
--text-display
Read by color

var(--colors-neutral-800)
Dark mode var(--colors-neutral-100)
--text-primary-paragraph
Read by color

var(--colors-neutral-700)
Dark mode var(--colors-neutral-300)
--divider-color
Read by border-block-end, border-block-start

var(--colors-alpha-black-10)
Dark mode var(--colors-alpha-white-10)

JavaScript

The NDS.Panel script loads after the page shows. Until it loads, each call loads it and returns a promise of the result, so await a call whose result you use.

Each method takes the panel element or its id.

Method Effect
NDS.Panel.open(panel, { focus }) Opens the panel, by the Stacking rules. For a lazy panel, pass its id: the element is not in the page yet. Pass { focus: false } when the page opens it on its own, so focus stays where the user is
NDS.Panel.close(panel) Closes the panel
NDS.Panel.toggle(panel) Opens or closes the panel
NDS.Panel.isOpen(panel) Returns true while the panel is open and not closing
NDS.Panel.init() Starts every .nds-panel on the page that has not started yet
NDS.Panel.create(panel) Starts one panel element
NDS.Panel.destroy(panel) Closes the panel at once and removes its listeners
Event Fired on Detail
nds:panel:opened .nds-panel { panel }, after the panel slides in
nds:panel:closed .nds-panel { panel }, after the panel slides out. When one panel replaces another, this fires before the new panel’s opened. A static panel that hides and comes back fires neither event
nds:panel:resized .nds-panel { panel, size }, after a resize button changes the size
nds:template:ready .nds-panel { id }, when a lazy panel joins the page
document.addEventListener('nds:panel:closed', function (e) { if (e.detail.panel.id === 'settings-panel') console.log('Settings closed'); }); NDS.Panel.open('settings-panel');

The full API is in the banner of _js/nds-panel.js.

Last Modified Date: 16/11/2026 - 09:13 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks