Generic Container
Add nds-empty to any block element. When it has no child elements, the placeholder renders centered inside.
<div class="nds-empty"></div>
In Lists
On <ul> and <ol> elements the placeholder is injected as an <li> so the list structure stays valid.
<ul class="nds-empty"></ul>
In Tables
Place nds-empty on the <table> itself. The placeholder row spans every column using colspan derived from the header, and a <tbody> is created automatically when one is missing.
| Name | Status | Updated |
|---|
<table class="nds-empty nds-table">
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>Updated</th>
</tr>
</thead>
</table>
Custom Message & Icon
Override the default text with data-empty-message and the default glyph with data-empty-icon. Either attribute updates its rendered element in place when the value changes at runtime.
<div class="nds-empty"
data-empty-message="You have no new notifications"
data-empty-icon="hgi hgi-stroke hgi-notification-off-01"></div>
Live Content Updates
The placeholder reacts automatically to DOM changes. Adding a real child hides it; removing the last real child brings it back. No manual refresh needed.
<ul id="reactive-list" class="nds-empty"></ul>
const list = document.getElementById('reactive-list');
// Add a real child. The empty placeholder disappears automatically.
const li = document.createElement('li');
li.textContent = 'New item';
list.appendChild(li);
// Remove the real child. The placeholder comes back on its own.
li.remove();
Built-in Features
Activates on any element with nds-empty. New containers added to the DOM later are picked up automatically.
Injects a valid child for the parent tag: <li> in lists, a spanning <tr> with <td colspan> in tables, a <div> elsewhere.
Renders Arabic or English text based on the page lang attribute with no configuration.
Placeholder appears when the container becomes empty and disappears the moment real content is added back.
Set data-empty-message on the container to replace the default text. Updates live when the attribute changes.
Call NDS.Empty.refresh(el) to force re-evaluation of a specific container from application code.
Usage Guidelines
Best Practices
- Use nds-empty on any container that can legitimately have zero items: search results, filtered lists, data tables, notification feeds, dashboards, user-generated collections
- Prefer nds-empty over a hand-rolled placeholder so all empty states across the site look and behave consistently
- Do not use it for loading or in-progress states. Use the Loading component while data is being fetched, then let nds-empty take over once the request resolves with no results
- Do not use it to communicate errors. Use an Alert with
data-status="error"so the user understands something went wrong rather than that the result set is genuinely empty - Write data-empty-message so it answers "why is this empty and what can I do next?" For example, "No results match your search" beats "Empty" because it implies the user can adjust the query
- Keep custom messages to a single short sentence. Longer guidance belongs in a paragraph outside the container or in linked help content
- Make sure the container has enough height for the placeholder to breathe. A minimum height of roughly 240 to 320 pixels keeps the icon and message visually centered
- Do not mix nds-empty with conditionally rendered "no results" markup in the same container. Pick one so the placeholder never appears twice
- When a table column count changes after initial render, call
NDS.Empty.refresh(el)so the placeholder row picks up the newcolspan
Data Attributes
| Attribute | Description |
|---|---|
data-empty-message |
Set on the .nds-empty container to override the default text. Any non-empty string wins over the built-in Arabic or English default. Changing the value at runtime updates the rendered message in place. |
data-empty-icon |
Set on the .nds-empty container to override the default icon. Value is the full class string applied to the placeholder's <i>. Use any icon system: UI icon (nds-icon nds-hgi-search-01) or content-font icon (hgi hgi-stroke hgi-notification-off-01). Changing the value at runtime updates the rendered icon in place. |
JavaScript API
The NDS.Empty API auto-initializes at page load and watches the DOM for new .nds-empty containers. Use NDS.Empty.refresh() when you need to force re-evaluation after an external DOM operation the observer cannot see (for example, a column-count change on a table).