Skip to main content
Login

Sign in to access your account

Expandable Content - National Design System

A box that limits long content to a set height, with a Show More button that appears only when the content is taller

Overview

Expandable Content is a box, nds-expandable, around the content, nds-expandable-content. The script measures the content. When it is taller than the max height, the script adds a Show More button.

Pick another component when:

  • the content is a set of sections with headings: Accordion
  • one line or a few lines of text must fit: Truncate Text

Markup

Preview

The National Digital Transformation Strategy sets a framework to modernize government services in all sectors. It has three pillars: the citizen experience, efficient operations, and decisions based on data.

Each ministry publishes a yearly plan. The plan lists the services that move online, the target dates, and the teams that own each service. Progress is reviewed every quarter.

Citizens sign in once with their national digital identity. The same account opens every government service, so a citizen does not register again for each portal.

Service owners measure completion rates, waiting times, and satisfaction scores. They publish the results on a public dashboard that any citizen can read.

The strategy also sets common standards for accessibility, security, and Arabic content. Every new service must meet them before it goes live.

<div class="nds-expandable"> <div class="nds-expandable-content nds-prose"> <p>The National Digital Transformation Strategy sets a framework to modernize government services in all sectors. It has three pillars: the citizen experience, efficient operations, and decisions based on data.</p> <p>Each ministry publishes a yearly plan. The plan lists the services that move online, the target dates, and the teams that own each service. Progress is reviewed every quarter.</p> <p>Citizens sign in once with their national digital identity. The same account opens every government service, so a citizen does not register again for each portal.</p> <p>Service owners measure completion rates, waiting times, and satisfaction scores. They publish the results on a public dashboard that any citizen can read.</p> <p>The strategy also sets common standards for accessibility, security, and Arabic content. Every new service must meet them before it goes live.</p> </div> </div>

Behavior

Group

Put nds-expand-all on the parent of several expandable boxes. Show More on one box then opens every box in the group, and Show Less closes them all. Only the boxes in the group itself follow: an expandable box inside a box’s content opens and closes by itself.

Built-in Features

  • Automatic Start

    The loader starts the script on every .nds-expandable. You write no script.

  • No Layout Shift

    CSS limits the content to the max height before the script runs. The page does not jump when the script starts.

  • Height Check

    The script measures the content again when its size changes. When the content fits, the script removes the limit and hides the button.

  • Fade

    Limited content fades out above the button. No text shows behind the button.

  • Bilingual Labels

    The button reads "Show More" and "Show Less" in English, and «عرض المزيد» and «عرض أقل» in Arabic, from the lang of the page.

  • Hidden Panels

    A box in a hidden panel stays limited until the panel shows. Tabs measures it again when its panel opens.

Best Practices

  • Use it for long text that most users do not read in full: descriptions, legal text, specifications, long lists.
  • Do not hide main actions or information that the user must read.
  • Do not write the button. The script builds it.
  • Write --max-height in px. The script cannot read other units, such as rem, and shows the button on content that fits.
  • Set a max height that shows enough text for the user to decide whether to read more. Below 80px, the first paragraph can be hidden.
  • Use a group for related items that the user compares, such as a comparison grid or a set of policy summaries.
  • After you add expandable boxes to the page, call NDS.Expandable.init().
  • After your script changes --max-height, call NDS.Expandable.refresh(). A hidden box measures itself again when it is shown.

API

Other Classes

Class Element Effect
nds-expand-btn the button the script builds Places the button at the bottom end of the box. Use it to style the button
nds-expandable-clip an element between .nds-expandable and .nds-expandable-content The script adds it, and CSS clips the element while the content is limited. Do not write it

Data Attributes

Attribute Element Effect
data-state~="expandable" .nds-expandable The script sets it when the content is taller than the max height, and removes it when the content fits. destroy() removes it. CSS adds the fade and places the button while it is set
data-state~="expanded" .nds-expandable The script sets it when the box opens, and removes it when the box closes or the content fits. destroy() removes it

CSS Custom Properties

Property Default Controls
--max-height 300px The height of the content while it is limited. Set it on .nds-expandable-content or on a parent, in px only. After you change it, call refresh()
--mask-fade-percentage 35% The length of the fade, as a share of the max height. The fade ends above the button. Set it on .nds-expandable

JavaScript

The NDS.Expandable 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.

The instance is on the box as el.ndsExpandable. It is there once the component starts: code that runs at page load waits for NDS.init.ready.

Method Effect
NDS.Expandable.init() Starts every .nds-expandable on the page that has no instance. The loader calls it. Call it after you add boxes to the page
NDS.Expandable.refresh() Measures every box again. Call it after you change --max-height
NDS.Expandable.create(el) Starts one box and returns its instance. Returns the running one when the box already has one, and null when it has no .nds-expandable-content
NDS.Expandable.destroy(el) The same as instance.destroy()
instance.expand() Opens the box. Does nothing on an open box
instance.collapse() Closes the box. Does nothing on a closed box
instance.toggle() Opens a closed box and closes an open one
instance.refresh() Reads --max-height and measures the box again
instance.getState() Returns isExpanded, hasButton (the script built the button, shown or hidden), maxHeight (px) and actualHeight (the full content height in px)
instance.destroy() Removes the button, the states and the size watch
Event Fired on Detail
nds:expandable:expanded .nds-expandable, after it opens container, content, button, isExpanded
nds:expandable:collapsed .nds-expandable, after it closes container, content, button, isExpanded

Both events bubble. In a group, each box fires its own event.

var box = document.querySelector('#policy-summary'); var expandable = NDS.Expandable.create(box); expandable.expand(); box.addEventListener('nds:expandable:collapsed', function (e) { console.log('Closed:', e.detail.content); });

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

Last Modified Date: 01/11/2026 - 05:15 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks