Skip to main content
Login

Sign in to access your account

Audit - National Design System

A check you run on a built page that lists NDS markup and CSS that fail with no error, and every name an NDS release changed

Overview

The audit reads a page after NDS starts and lists the problems that show no error: a filter that binds to nothing, an icon with no registration, a skip link to a missing id. It also finds each class, attribute, id, custom property and window setting that an NDS release renamed or removed, in the page’s markup and in the site’s own CSS.

NDS.init.audit() runs it and returns the findings as an array, so you and an AI coding agent can read them. The audit is its own bundle. A page loads it only on the first call, so a production page downloads none of it.

Pick another component when:

  • you need the list of changed names by release: Migration

Usage

Run it in the browser console, or from a test, once the page has loaded.

const findings = await NDS.init.audit(); const errors = findings.filter(f => f.severity === 'error');

Run one group or one rule. quiet keeps the console clear.

NDS.audit.run({ group: 'migration', quiet: true }); NDS.audit.run({ rule: ['id-reference', 'skip-link'] });

Skip markup you cannot change yet, such as a block your CMS writes. Name the rules to skip, or leave the value empty to skip them all.

<div class="cms-legacy-block" data-nds-audit-ignore="migration-markup"> … </div>

Add a rule of your own. It runs with the others on every call.

NDS.audit.addRule({ id: 'service-card-link', group: 'structure', severity: 'error', check(ctx) { ctx.find('.service-card') .filter(card => !card.querySelector('a')) .forEach(card => ctx.report(card, 'a service card has no link.', 'Add the service page link to the card.')); } });

Behavior

Severity

Each finding has a severity. error is broken now: a part gets no style or behavior, or shows the wrong text. warn works today but is wrong, or goes away at the next major release. info is a note: a custom property that NDS never read, or a tip.

Tips

The practice group holds tips from the Best Practices of the doc pages, such as a section inside a section. A tip is info: its line starts with tip:, and it never means that the page is broken. To run the audit without tips, name the other groups: NDS.audit.run({ group: ['page', 'structure', 'migration', 'i18n'] }).

Console Output

Each finding prints one line that starts with [NDS.audit] and its rule id, then the problem, the fix and a docs link. An error prints as a console error, a warning as a warning. A last line counts the errors, warnings and notes. The element prints with its line, so the console can show it on the page.

Migration Checks

migration-markup checks the classes, attributes, ids and inline custom properties on the page, and the window settings NDS read before. migration-css checks the site’s own CSS. A name used on many elements is one finding, with the count and the first element.

A generic name, such as sr-only, counts only inside NDS markup. When the site’s own CSS styles that class, the audit treats it as the site’s class and skips it.

Site CSS

migration-css, css-order, nds-restyle, global-element-css and token-dark check only the site’s own style sheets, inline <style> included. They skip the NDS style sheets, the NDS <style> in the head, an event pack’s style and any sheet from another origin.

css-order, token-dark, unknown-class and part-outside also read the NDS style sheets, to learn the NDS classes and tokens. When those sheets come from another origin, these four check nothing.

Limits

The audit reads the page, not the scripts. An old method name or an event listener in your JavaScript does not show: the release notes list those. An icon name inside a JavaScript string does not show either. The icon check reads the icon style sheet, so run the audit after the page has loaded. The legacy check knows only the common libraries: a clean result does not prove that a page has no other UI library.

Built-in Features

  • No Bytes in Production

    The audit is a bundle of its own that the first call loads. A page that never calls it downloads none of it.

  • Findings as Data

    The call returns an array of findings. Each one has `rule`, `group`, `severity`, `message`, `fix`, `docs`, `el` (the element) and `count`. A test or an AI coding agent reads it with no console parsing.

  • Every Release's Changes

    The migration checks know every name that changed since 1.0.0, with today's name and the release that changed it.

  • Your CSS Too

    Old class names and custom properties in your own style sheets show, with the sheet and the rule that holds them. So do rules on bare elements and token overrides with no dark value.

  • Silent Failures

    Each structure rule covers a mistake that shows no error, such as a target id that names nothing or a list held in its loading skeleton.

  • Your Own Rules

    NDS.audit.addRule() adds a check for your own markup, and it reports like the built-in ones.

Best Practices

  • Run the audit on each page you build or change. After an NDS upgrade, run it on each page of the site: it sees only the page it runs on.
  • Fix the errors first. A warning still works, so it can wait for a later pass.
  • Read the returned array in a test or an agent. The console lines are for people.
  • Name the rule in data-nds-audit-ignore. An empty value hides every rule, including the ones you still need.
  • Leave enableLogging off in production. It loads the audit and logs every component on each page.

API

Rules

Rule Group Severity Finds
lang-dir page warn No lang on <html>, or a dir that does not match the language
css-missing page error The NDS main style sheet did not apply
skip-link page warn, error No skip link, a skip link to a missing id (error), or one that lands on <main>
main-flex page warn A wrapper between <body> and <main> that stops <main> from growing
content-layout-child page warn An element in .nds-content-layout that is not .nds-content or .nds-sidemenu. An element that renders nothing, such as a <template>, passes
sidemenu-missing page warn nds-has-sidemenu on an element with no .nds-sidemenu child, or a hidden one: the content squeezes into the menu column
alert-as-page page warn A view whose only visible content, apart from a tab list, a breadcrumb or pagination, is an .nds-alert outside a tab panel: a view that cannot show its content (sign in, no permission, not found, a failed load) is a Status Section
status-section-alone page warn A visible Status Section with other content sections on the page. A status section is the whole page, with only the page hero beside it. Show an outcome among other content in a status card
content-layout-once page warn More than one .nds-content-layout on the page, or one inside another: the page grid is set once
title-repeat page warn A heading, block title or card title in <main> with the same text as the page’s h1. A table of contents title and a slider’s clone slides pass
sidemenu-pair page warn A .nds-sidemenu outside a layout with nds-has-sidemenu
legacy-library page warn A common legacy UI library loaded on the page, such as jQuery, Select2, DataTables, Bootstrap CSS or Font Awesome
bundle-tag page warn A tag in the page for a bundle the loader adds itself, such as nds-delegated.min.js
inline-defer page warn An inline <script defer>: without src, defer does nothing and the code runs before NDS loads
img-size page warn An <img> whose width and height give a different shape from the picture, so it stretches or the layout jumps. It skips images that have not loaded, and an SVG with no size of its own
native-date-time page warn A browser date or time field (type="date", month, week, datetime-local, time) where the Date Picker or Time Picker belongs
style-blocked page warn A knob in a style attribute that the page’s Content Security Policy blocked, so it never applies. One finding for the page, with the count
toolbar-part structure warn An nds-toolbar-* part (row, start, end, text) outside a .nds-toolbar: it still lays out as a bar, but stacked rows touch and the bar loses its gap. One finding per bar
toolbar-search-row structure warn A search box whose line holds more than one other item. The applied-filters and suggestion lines do not count: they take a line of their own
toolbar-applied structure warn Applied filters (.nds-filter-applied) outside a toolbar, above the search or filter they show, or in the same row as them
toolbar-sizes structure warn Items on one toolbar line with different heights, such as a 32px nds-md button beside a 40px one. It skips hidden items
table-min-width structure warn On a desktop, a table with an actions column whose --min-width is wider than its box, so users scroll sideways to reach a row’s actions. Content that widens a table does not count. Phones and tablets are skipped
form-row-align structure warn Fields side by side whose inputs do not start level, because something above one input pushes it down, such as an Info line under its label or a label on two lines. A message under an input does not count, unless the row centers its fields (a flex row, a table): then a field that grows with its message moves the others, and the finding says to align the row to the top, or to add nds-baseline to a table. A stack of fields in one row slot, such as a date over a time, counts as its top field. It skips checkboxes, radios, switches and uploads
parts-touch structure warn Two NDS parts, or a part and a paragraph or note, that follow each other in the markup and sit one under the other with no space between them, anywhere on the page, such as fields dropped straight into a tab panel. A table counts by its wrapper, and an nds-prose article counts as a part. It skips a section the browser has not laid out yet
hero-aside-split structure warn A hero with nds-aside on a page with side info, where the element right after the hero is not .nds-content-layout. The side info then stays below the hero, such as when an Angular component’s tag wraps the hero
price-text structure warn A price written as text with a riyal word or sign, such as 1200 ريال or SAR 600, in a table cell, a field or a figure. Sentences in prose, paragraphs and descriptions pass. Write the number in nds-number-format with data-currency="SAR"
card-status-place structure warn A status tag (.nds-tag with data-status) in a card’s tag row or meta. A card’s state goes in .nds-card-corner; the tag row keeps standard tags
card-value-number structure warn A .nds-card-value with only bare text inside. Bare text shows as the small unit, not the value. Put a number in nds-number-format, and a word such as Free in a <span>
status-tag-icon structure warn An icon in a status tag (.nds-tag with data-status). The tag shows its dot and the icon, two markers. Drop the icon: the label names the status
tag-state-color structure warn A table column whose one-tag cells hold standard tags in more than one color, or with more than one state icon (a check, a clock, an alert). Colors or state icons that change by row show a state: give every tag data-status and drop the color classes and icons. A category column with an icon per category passes
i18n-pack i18n error The language file of the page did not load. A language NDS does not ship is a warn, and only when window.NDS_I18N_LANGS has no words for it
i18n-override i18n warn A section or key in window.NDS_I18N or window.NDS_I18N_LANGS that no NDS component or getStrings() call has, so it changes nothing
filter-unclaimed structure error data-filter-items that no filter claimed, so it stays in its skeleton
filter-no-target structure error A .nds-filter with no data-filter-target
paged-no-nav structure error A .nds-paged-content with no pagination nav
icon-unregistered structure error An nds-hgi-* icon that is not in the registered set. While the icon style sheet is missing, one finding names it instead of one per icon
font-icon-unknown structure error A font icon (hgi hgi-stroke hgi-*) whose name the HGI stroke rounded set lacks, so it shows nothing. It runs once the HGI style sheet has loaded
icon-tag structure error A UI icon (nds-icon nds-hgi-*) on a tag other than <i>. The icon styles apply to <i> only, so it shows nothing
icon-only-btn structure warn A button in a field’s .nds-form-action with an icon, no text and no nds-icon-only: it keeps its text padding and renders wider than tall
hidden-label-icon structure error A button whose label data-hidden hides has no icon or avatar: where the label hides, it shows an empty box
prose-section-title structure warn A heading inside nds-prose with nds-section-title: it renders at the page title’s size, not the text’s. Prose already styles a bare h2 to h6
name-on-display structure error name on the text box of a Custom Select or Time Picker, or on an OTP digit box. The form then sends the text it shows, not the value
button-name structure error A button or link with no name: no text, aria-label, aria-labelledby, title or image alt, such as an icon-only button. A screen reader announces it with no words. It skips what a screen reader never reaches, such as an aria-hidden loop clone
field-label structure error A form field with no label: no <label>, aria-label, aria-labelledby, title or placeholder. A screen reader announces it with no name
img-alt structure error An <img> with no alt: a screen reader reads its file name. alt="" marks a picture that only decorates
nav-current structure warn A main nav link to the current page with no data-state="current"
id-reference structure error A data-*-target, data-auto-pagination or data-copy-target value that names no element, read the way its component reads it. An attribute that takes a bare id reports #list and names the fix, list. An id inside a <template> counts as present
aria-controls structure warn An aria-controls id that no element has, inside or outside a <template>
id-duplicate structure error One id on two or more elements, outside SVG: a lookup by id reaches only the first
sort-target-owned structure warn A data-sort-target on a list that a filter or a table already sorts
stepper-submit structure warn data-stepper-control on a submit button, where it does nothing
css-order page warn A site style sheet that styles NDS classes or tokens at the same specificity as the NDS style sheet that declares them, but loads before it, so NDS wins every tie and the override does nothing. A theme right after the critical CSS passes, and so does a more specific selector, such as :root:root
nds-restyle page warn A rule in the site’s own CSS that restyles NDS classes with no project class, id or data-* attribute in its selector. One finding per sheet. It skips a rule that sets only custom properties
global-element-css page warn A rule in the site’s own CSS on bare elements, such as body, h1 or a: it reaches every NDS element on the page. One finding per sheet. It skips a rule that sets only custom properties
token-dark page warn A token override in the site’s own CSS that has no dark value where NDS has one, sets only some states of a family, or misses the dark-area selector on a page with dark areas. See Tokens
migration-markup migration error, info A renamed or removed name (error) in the markup, or an old window setting. A deprecated name is info: it still works, and the message names its replacement
migration-css migration error, info The same names in the site’s own CSS. A deprecated name, or a custom property that NDS never read, is info
badge-text migration warn A badge count written as text, not in data-count. The text joins the button’s visible label, so an accessibility checker reports the button’s name
unknown-class structure warn An nds- class that no NDS style sheet, doc or script has, so it gets no NDS style or behavior. An old name is left to migration-markup
required-part structure error A part or attribute that a component’s script needs to work, missing with no console warning, such as a tab with no panel or a date field outside its .nds-form-control. Each component lists these in the Requires lines of its script’s banner
part-outside structure warn A component part outside its component, such as .nds-card-title with no .nds-card around it. It skips a part that NDS also styles on its own
area-no-dark structure warn An area word (oncolor, neutral or gradient) in data-theme without dark, which changes nothing: data-theme="dark neutral". primary alone is fine: it paints the light tint
area-gradient-no-fill structure warn gradient in data-theme without primary. There is no neutral gradient, so the word does nothing
area-two-fills structure warn Two fill words (primary and neutral) in one data-theme. Keep one
area-primary-no-oncolor structure warn data-theme="dark primary" without oncolor. The parts keep their dark looks on a primary fill: write data-theme="dark oncolor primary"
card-link-nested practice info A link or a button inside a clickable card (a.nds-card, button.nds-card)
section-nested practice info A section inside a section. Divide a section body with .nds-block
card-actions-place practice info .nds-card-actions inside .nds-card-content, not after it, or a form’s .nds-form-actions inside a modal’s .nds-card-content, where the buttons scroll with the content
modal-scroll-more practice info A modal whose .nds-card-content holds anything besides a .nds-card-text, with no .nds-scroll-more on it or as its child. It checks the markup, not the overflow, since content can grow after the run
switch-reverse-end practice info A switch at the end of a line, in a section action or a toolbar end, without nds-reverse. It skips a stacked switch
tag-kind-mix practice info A table column whose one-tag cells mix status tags (data-status) and standard tags. A state takes a status tag on every row
dark-nested practice info data-theme="dark" inside a dark area, which is already dark. It skips an inner element that carries an area word
prose-nested practice info .nds-prose inside .nds-prose
loading-field practice info nds-loading on a form field, which has a loading look of its own
voice-secret practice info Voice input on a password, OTP or read-only field, or on a select
dark-selector practice info [data-theme="dark"] in the site’s own CSS, where [data-theme~="dark"] also matches a data-theme with more than one value
palette-scope practice info A palette token (--colors-*) set below :root in the site’s own CSS. The tokens built from the palette read it at :root

Data Attributes

Attribute Element Effect
data-nds-audit-ignore any element The audit skips the element and everything in it. The value names the rules to skip, separated by spaces or commas. An empty value skips every rule

Configuration

Global Default Effect
NDS_AUDIT_RULES — An array of rule definitions that every run reads. Use it to set rules in a script that runs before NDS
NDS_INIT_CONFIG.enableLogging false Runs the audit once the page has loaded. See Init

Findings

Field Holds
rule The id of the rule
group page, structure, i18n or migration
severity error, warn or info
message The problem
fix What to change
docs A link to the docs page of the part, when the rule has one
el The element, or none for a page-wide finding
count How many elements or CSS rules use the name, for a migration finding

JavaScript

Method Effect
NDS.init.audit() Runs every rule and returns the findings. The first call loads the audit and returns a promise of them
NDS.audit.run(options) Runs the rules once and returns the findings. group and rule take a name or an array, and quiet: true prints nothing. Before the audit loads, the call loads it and returns a promise
NDS.audit.addRule(definition) Adds a rule, or replaces the rule with the same id. It takes id, group, severity, docs and check(ctx). Before the audit loads, the call loads it first
NDS.audit.rules Every rule, in run order
ctx.find(selector) In check: the matching elements, without the ones in <code> or skipped by data-nds-audit-ignore
ctx.report(el, message, fix, severity) In check: adds a finding. severity overrides the rule’s own
// Fail a page test on any error const findings = await NDS.init.audit(); const errors = findings.filter(f => f.severity === 'error'); if (errors.length) throw new Error(errors.map(f => `${f.rule}: ${f.message} ${f.fix}`).join('\n'));

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

Last Modified Date: 20/11/2026 - 08:55 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks