Overview
Truncate Text is one class, nds-truncate, and one custom property, --truncate, which sets how many lines show.
Pick another component when:
- the user must be able to open the full text on the page: Expandable Content
Markup
The unified portal gives access to more than 200 government services from 35 ministries. Citizens can submit applications, track requests, book appointments and get notices about their open requests. The portal supports biometric sign-in, digital signatures and secure document uploads.
Variants
The card title stays at one line. A Lines option sets --truncate in the style attribute of the description.
| Group | Option | Markup | On element | Use |
|---|---|---|---|---|
| Lines | 1 (default) | — | — | Titles, labels and list items |
| Lines | 2 | --truncate: 2 |
.nds-card-description |
Short descriptions, where one line cuts too much |
| Lines | 3 | --truncate: 3 |
.nds-card-description |
Previews where the first sentence matters |
| Lines | 4 | --truncate: 4 |
.nds-card-description |
Longer previews |
Built-in Features
-
CSS Only
One class and no JavaScript. There is nothing to start, and nothing to clean up.
-
Any Text Element
Works on a heading, a paragraph, a
<span>or a<div>. A<span>becomes a block, so it takes its own line. -
Container Width
When the container gets wider or narrower, the text clips at the new width.
-
Full Text for Screen Readers
The class clips only what shows. The full text stays in the page, so a screen reader reads all of it.
Best Practices
- Use it for text that can be too long for its space: card titles and descriptions, table cells, menu labels and list items.
- Use 1 line for titles and labels, 2 for short descriptions and 3 for previews.
- Give the user another way to read the full text: a
titleattribute, a Tooltip, or a link to the full page. - Do not clip text the user must read to finish a task, such as form labels, error messages or legal text.
- If every card description is clipped, the text is too long. Shorten the text first.
- The text clips only when it needs more lines than
--truncateallows. To clip a short text, give its element amax-width. - The class has zero specificity, so a component rule that sets
displayon the same element wins, and the text does not clip. When you add it to a part of another component, check that the ellipsis shows.
API
CSS Custom Properties
Set it in the style attribute of the element with nds-truncate: style="--truncate: 3". On a parent, it changes every nds-truncate element inside it.
| Property | Default | Controls |
|---|---|---|
--truncate |
1 |
How many lines show before the ellipsis. A whole number above 0 |