Standard Expandable Content
Wraps any block of content in a height-constrained container. A "Show More" button appears automatically when the content overflows.
Expandable Card
Apply expandable behavior directly to a card component to constrain long descriptions or detail blocks within a defined height
Sibling Sync
Wrap multiple expandable containers in an nds-expand-all parent so expanding or collapsing one toggles all siblings in sync
Built-in Features
Activates on every .nds-expandable element at page load. The toggle button is added only when the content actually overflows.
Continuously monitors content size and shows or hides the toggle button when the viewport or container dimensions change.
A configurable gradient mask fades the bottom of truncated content, signaling that more content is available below.
The toggle button label switches between English ("Show More" / "Show Less") and Arabic automatically based on the page language.
Wrap multiple expandable containers in an nds-expand-all parent and expanding one will expand all siblings together.
Expand, collapse, toggle, and query state through instance methods on element.ndsExpandable.
Usage Guidelines
Best Practices
- Use expandable content to keep pages scannable when a section contains long descriptions, legal text, detailed specifications, or extended lists that most users will not need to read in full
- Use inside Cards to constrain card body height while still exposing a preview of the full content
- Use the
nds-expand-allwrapper when multiple related items should reveal their content together, such as a comparison grid or a set of policy summaries - Do not use expandable content for short text that fits within the default 300px limit. The toggle button will not appear, but the extra wrapper adds unnecessary DOM weight
- Do not use expandable content to hide primary actions or critical information the user must see. Use an Accordion for structured show/hide sections with headings
- Set
--max-heightto a value that shows enough content for the user to judge whether they want to read more. Avoid values below 80px as they may obscure the first paragraph entirely - When adding expandable content to dynamically loaded elements, call
NDS.Expandable.reinit()after inserting the new HTML to initialize the new containers - Place
--max-heighton the.nds-expandable-contentelement (not the outer wrapper) when the expandable container has its own padding or borders that should remain visible - Use
recheckHeight()orNDS.Expandable.recheckHeights()after content changes (AJAX loads, tab switches) to re-evaluate whether the toggle button is still needed
CSS Custom Properties
| Property | Default | Description |
|---|---|---|
--max-height | 300px | Maximum visible height before the content is clipped and the toggle button appears. Set on .nds-expandable or .nds-expandable-content |
--mask-fade-percentage | 35% | Percentage of the content height that fades to transparent when collapsed. Higher values create a longer gradient |
JavaScript API
The NDS.Expandable API provides methods to initialize containers, control expand/collapse state, and listen for state change events. Instances are accessible via element.ndsExpandable.