Skip to main content
Login

Sign in to access your account

Hidden - National Design System

CSS utilities that hide an element always, at chosen screen widths, or on screen only while screen readers still read it

Overview

Hidden is a set of CSS tools that remove an element from view. The native hidden attribute hides an element at every width. data-hidden hides it only inside the screen widths it names. The sr token in data-hidden, and the nds-sr-only class, hide it on screen but keep it for screen readers.

Pick another component when:

  • the content shows and hides when the user clicks a heading: Accordion
  • the content changes with a tab: Tabs
  • actions that do not fit on a phone move into a menu: Dropmenu
  • long text stops after a number of lines: Truncate Text

Markup

Preview
<button class="nds-btn nds-neutral" type="button"> <i class="nds-icon nds-hgi-share-01" aria-hidden="true"></i> <span class="nds-label" data-hidden="sm">Share</span> </button>

Built-in Features

  • The hidden Attribute Wins

    An element with hidden stays hidden even when a component or a utility gives it a flex or grid display. The rule uses display: none !important.

  • Exact Width Ranges

    Each data-hidden token hides the element only inside its own range. Hiding at MD does not also hide at SM.

  • Combined Ranges

    Tokens separated by spaces add up. data-hidden="sm md" hides the element below 960px, and data-hidden="md lg" shows it on phones only.

  • Screen Reader Text

    The sr token and nds-sr-only remove the element from the screen, but screen readers still read it. A button that shows only its icon keeps its name.

  • CSS Only

    The hidden rule loads with the page's first styles, so a hidden element never shows before the main CSS arrives. There is nothing to initialize.

Best Practices

  • Use hidden for state: a panel, a menu or a step that your script shows and hides. Use data-hidden for an element that has no place at some screen widths, such as a topbar widget or secondary details.
  • One element can carry hidden and data-hidden. Either one hides it.
  • Use data-hidden instead of your own media query. Its ranges match the NDS breakpoints.
  • hidden and data-hidden without sr also hide the element from screen readers. Add sr when the text must still be read.
  • To show only a button’s icon on phones, write data-hidden="sm sr" on its label. Never hide the label without sr: the button loses its name.
  • A button whose label data-hidden hides is a square icon button in that range, as nds-icon-only makes it.
  • Use nds-sr-only for text that only screen readers need at every width, such as a word that tells screen readers what a number badge counts.
  • Do not hide a main action on phones. Move it into a Dropmenu, so the user can still reach it.
  • A hidden element still loads its images and frames. Leave heavy content out of the markup instead of hiding it.

API

Classes

Class Element Effect
nds-sr-only Any element Hides the element on screen at every width. Screen readers still read it
nds-hidden Any element Hides the element, the same as hidden. NDS scripts write it to match data-state="hidden": write hidden or data-state yourself, not this class

Data Attributes

Attribute Element Effect
hidden Any element Hides the element at every width and from screen readers, over any display value. Set it yourself, or let a component’s script set it
data-hidden Any element Hides the element inside each width range it names: sm (narrower than 600px), md (600px to 959px), lg (960px and wider), or print (on paper only, see Print). Separate tokens with spaces. Add sr to hide it on screen only
data-state Any element The hidden token hides the element, the same as hidden. Component scripts write it through NDS.state
Last Modified Date: 20/10/2026 - 05:08 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks