Skip to content

Forms

Every form class styles the native element, so validation, autofill, keyboard input and assistive technology keep working. Wrap each value in a nw-field with a nw-label, a control and optional hint and error text.

nw-input is the shared well for text controls: <input> of any text-like type, textarea.nw-input and, through the same paint variables, nw-select. The well is the deepest surface in dark flavors and the lightest in lumen, so it reads as a well on both a canvas and a panel.

A host name without a protocol.

The key must be at least 12 characters.

<div class="nw-field">
<label class="nw-label" for="f-host">Host</label>
<input class="nw-input" id="f-host" type="text" placeholder="relay.nyxwire.dev" aria-describedby="f-host-hint" />
<p class="nw-field-hint" id="f-host-hint">A host name without a protocol.</p>
</div>
<div class="nw-field">
<label class="nw-label nw-label-required" for="f-key">Access key</label>
<input class="nw-input" id="f-key" type="password" value="hunter22" aria-invalid="true" aria-describedby="f-key-error" />
<p class="nw-field-error" id="f-key-error">The key must be at least 12 characters.</p>
</div>
<div class="nw-field">
<label class="nw-label" for="f-region">Region (read-only)</label>
<input class="nw-input" id="f-region" type="text" value="eu-north" readonly />
</div>
<div class="nw-field">
<label class="nw-label" for="f-port">Port (disabled)</label>
<input class="nw-input" id="f-port" type="number" value="8443" disabled />
</div>
<div class="nw-stack nw-stack-sm">
<input class="nw-input nw-input-xs" type="text" placeholder="Extra small" aria-label="Extra small input" />
<input class="nw-input nw-input-sm" type="text" placeholder="Small" aria-label="Small input" />
<input class="nw-input" type="text" placeholder="Medium (default)" aria-label="Medium input" />
<input class="nw-input nw-input-lg" type="text" placeholder="Large" aria-label="Large input" />
</div>
<div class="nw-stack nw-stack-sm">
<input class="nw-input nw-input-secondary" type="text" placeholder="Secondary ring on focus" aria-label="Secondary input" />
<input class="nw-input nw-input-success" type="text" value="Verified" aria-label="Success input" />
<input class="nw-input nw-input-ghost" type="search" placeholder="Ghost: no well until hover" aria-label="Ghost search" />
<input class="nw-input" type="file" aria-label="Upload a config file" />
</div>
Class / selector Effect
nw-input The well: hairline border, focus ring, placeholder in the subtle ink. Medium by default.
nw-input-xs, -sm, -md, -lg Control heights 1.75rem, 2rem, 2.5rem (default) and 3rem. On coarse pointers the text never drops under 16px, so iOS does not zoom in.
nw-input-primary … nw-input-danger Colors the resting border and the focus ring with one of the eight intents.
nw-input-ghost No fill or border until hover; for inline editing and toolbars.
[aria-invalid="true"], :user-invalid Danger border and ring. Always wins over an intent class.
[readonly] Quiet well, value stays selectable.
:disabled, [aria-disabled="true"] Quiet well and ink rather than translucency.
[type="number"], date and time types Tabular numerals. File inputs get a styled selector button; color inputs a swatch.

There is no separate class: textarea.nw-input uses the same well with no fixed height and vertical resizing.

Markdown is supported.

<div class="nw-field">
<label class="nw-label" for="f-notes">Change notes</label>
<textarea class="nw-input" id="f-notes" rows="3" placeholder="What changed on this relay?"></textarea>
<p class="nw-field-hint">Markdown is supported.</p>
</div>

nw-select styles a native <select>. The caret is painted with gradients because the element has no pseudo-elements, and multiple or a size above 1 turns it into a list box without a caret. The option colors theme the platforms that honor them; the popup itself belongs to the browser. The same class works on a custom listbox trigger (a <button> or role="combobox"), where aria-expanded, data-state="open" and data-placeholder describe it; that is how the Vue NwSelect reuses it.

Pick an accent.

<div class="nw-field">
<label class="nw-label" for="f-flavor">Flavor</label>
<select class="nw-select" id="f-flavor">
<option>nocturne</option>
<option>twilight</option>
<option>abyss</option>
<option>lumen</option>
</select>
</div>
<div class="nw-field">
<label class="nw-label" for="f-accent">Accent (small, invalid)</label>
<select class="nw-select nw-select-sm" id="f-accent" aria-invalid="true">
<option value="">Choose an accent</option>
<optgroup label="Cool">
<option>indigo</option>
<option>ice</option>
<option>arc</option>
</optgroup>
<optgroup label="Warm">
<option>flare</option>
<option disabled>alarm (reserved)</option>
</optgroup>
</select>
<p class="nw-field-error">Pick an accent.</p>
</div>
<div class="nw-field">
<label class="nw-label" for="f-nodes">Nodes (multiple)</label>
<select class="nw-select" id="f-nodes" multiple size="4">
<option selected>hel-01</option>
<option>fra-02</option>
<option selected>ams-03</option>
<option>sto-04</option>
</select>
</div>
Class / selector Effect
nw-select The input well plus a painted caret.
nw-select-xs … -lg The input sizes.
nw-select-primary … -danger The input intents.
[multiple], [size] List box: no caret, rows sized to the content.
[aria-expanded="true"], [data-state="open"] A custom trigger whose list is open keeps its focus paint and flips the caret.
[data-placeholder] A custom trigger showing its placeholder uses the subtle ink.

nw-input-group joins inputs, selects, buttons and nw-input-addon text or icons into one control: inner corners square off and borders collapse. One size class on the group (nw-input-group-xs to -lg) sizes every child.

https:// :443
<div class="nw-input-group">
<span class="nw-input-addon">https://</span>
<input class="nw-input" type="text" placeholder="relay.nyxwire.dev" aria-label="Relay address" />
<span class="nw-input-addon">:443</span>
</div>
<div class="nw-input-group">
<input class="nw-input" type="search" placeholder="Search nodes" aria-label="Search nodes" />
<button type="button" class="nw-btn">Search</button>
</div>
<div class="nw-input-group nw-input-group-sm">
<span class="nw-input-addon"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg></span>
<input class="nw-input" type="text" placeholder="Small group" aria-label="Filter" />
<select class="nw-select" aria-label="Scope"><option>All</option><option>Online</option></select>
</div>
Class Effect
nw-input-group Joins its children; the focused child rises so its ring is not hidden.
nw-input-addon Static text or an icon at either end, on the sunken fill.
nw-input-group-xs, -sm, -md, -lg Sizes every input, select, button and addon in the group at once.

Checkbox and radio: .nw-checkbox, .nw-radio

Section titled “Checkbox and radio: .nw-checkbox, .nw-radio”

Both are drawn on the native <input> from tokens, so :checked, :indeterminate, :disabled and :focus-visible keep working and the mark survives forced colors. The visible box is small by design, but each control has a hit area of at least 24px, and a wrapping nw-label makes the whole row a target.

Alerts
Routing
Intents and sizes
<fieldset class="nw-field-group">
<legend class="nw-field-legend">Alerts</legend>
<label class="nw-label"><input class="nw-checkbox" type="checkbox" checked /> Latency above 100 ms</label>
<label class="nw-label"><input class="nw-checkbox" type="checkbox" /> Packet loss</label>
<label class="nw-label"><input class="nw-checkbox" type="checkbox" data-indeterminate /> Some regions (indeterminate)</label>
<label class="nw-label"><input class="nw-checkbox" type="checkbox" disabled /> Hardware faults (disabled)</label>
<label class="nw-label"><input class="nw-checkbox" type="checkbox" aria-invalid="true" /> Accept the terms (invalid)</label>
</fieldset>
<fieldset class="nw-field-group">
<legend class="nw-field-legend">Routing</legend>
<label class="nw-label"><input class="nw-radio" type="radio" name="f-route" checked /> Lowest latency</label>
<label class="nw-label">
<input class="nw-radio" type="radio" name="f-route" />
<span class="nw-label-text">Lowest cost<span class="nw-field-hint">Routes through the cheapest uplink, even if slower.</span></span>
</label>
<label class="nw-label"><input class="nw-radio" type="radio" name="f-route" disabled /> Pinned (disabled)</label>
</fieldset>
<fieldset class="nw-field-group">
<legend class="nw-field-legend">Intents and sizes</legend>
<div class="nw-cluster">
<input class="nw-checkbox nw-checkbox-sm nw-checkbox-secondary" type="checkbox" checked aria-label="Small secondary" />
<input class="nw-checkbox nw-checkbox-success" type="checkbox" checked aria-label="Success" />
<input class="nw-checkbox nw-checkbox-lg nw-checkbox-danger" type="checkbox" checked aria-label="Large danger" />
<input class="nw-radio nw-radio-sm nw-radio-tertiary" type="radio" name="f-sizes" checked aria-label="Small tertiary" />
<input class="nw-radio nw-radio-warning" type="radio" name="f-sizes" aria-label="Warning" />
<input class="nw-radio nw-radio-lg nw-radio-info" type="radio" name="f-sizes" aria-label="Large info" />
</div>
</fieldset>
Class / selector Effect
nw-checkbox, nw-radio The control. Checked and indeterminate fills take the intent; the mark is the on-accent ink.
nw-checkbox-primary … -danger (same for radio) Intent of the checked control.
nw-checkbox-sm, -md, -lg (same for radio) 14px, 16px (default) and 20px boxes.
:indeterminate A dash. Set it from script (input.indeterminate = true); there is no attribute.
[aria-invalid="true"], :user-invalid Danger border.
nw-label > .nw-checkbox Aligns the control to the first line of a wrapping label, through the lh unit.

A switch is a checkbox with role="switch", for a setting that applies at once. Off is a well with a neutral thumb, on is the intent with the on-accent thumb. The thumb moves on the compositor and squashes under the pointer without changing the track’s box. For a setting that only applies on submit, use a checkbox.

<label class="nw-label"><input class="nw-switch" type="checkbox" role="switch" checked /> Live telemetry</label>
<label class="nw-label"><input class="nw-switch nw-switch-sm nw-switch-success" type="checkbox" role="switch" /> Auto-failover (small, success)</label>
<label class="nw-label"><input class="nw-switch nw-switch-lg nw-switch-secondary" type="checkbox" role="switch" checked /> Night mode (large, secondary)</label>
<label class="nw-label"><input class="nw-switch" type="checkbox" role="switch" disabled /> Maintenance lock (disabled)</label>
Class Effect
nw-switch The track and thumb on <input type="checkbox" role="switch">.
nw-switch-primary … -danger Intent of the on state.
nw-switch-sm, -md, -lg Track sizes.
[dir="rtl"] The thumb travels the other way.

nw-slider styles <input type="range">, so keys, touch and assistive technology keep working. The track fills up to the thumb in the intent color. WebKit and Blink have no progress pseudo-element, so the fill position is an input: set --_slider-value to the value as a percentage on every input event. Without it, the slider still works and Firefox still fills it natively; only the WebKit fill is missing.

<div class="nw-field">
<label class="nw-label" for="f-gain">Gain <output for="f-gain">40</output></label>
<input class="nw-slider" id="f-gain" type="range" min="0" max="100" value="40" />
</div>
<div class="nw-field">
<label class="nw-label" for="f-buffer">Buffer, small and secondary <output for="f-buffer">64</output></label>
<input class="nw-slider nw-slider-sm nw-slider-secondary" id="f-buffer" type="range" min="16" max="256" step="16" value="64" />
</div>
<div class="nw-field">
<label class="nw-label" for="f-load">Load cap, large and warning <output for="f-load">80</output></label>
<input class="nw-slider nw-slider-lg nw-slider-warning" id="f-load" type="range" min="0" max="100" value="80" />
</div>
<div class="nw-field">
<label class="nw-label" for="f-locked">Locked</label>
<input class="nw-slider" id="f-locked" type="range" value="30" disabled />
</div>
Class / property Effect
nw-slider Track, fill and thumb. The focus ring is on the whole control, so it survives forced colors.
nw-slider-primary … -danger Fill and thumb intent.
nw-slider-sm, -md, -lg Track and thumb sizes. The hit area stays at least 24px tall.
nw-slider-vertical A vertical control (writing-mode), at least 6rem tall; give it a height.
--_slider-value The filled percentage, for example style="--_slider-value: 40%". The demo script below keeps it in sync.

A chip is a filter, a selected value or a removable token. At rest it is quiet, so a row of chips does not read as a row of primary buttons; the selected state carries the intent. Select it with aria-pressed, aria-checked, aria-selected or data-state="on", or put a checkbox or radio inside a label chip.

hel-01 ams-03
<div class="nw-cluster" role="group" aria-label="Filter by region">
<button type="button" class="nw-chip" aria-pressed="true"><span class="nw-chip-check" aria-hidden="true"></span>Europe</button>
<button type="button" class="nw-chip" aria-pressed="false"><span class="nw-chip-check" aria-hidden="true"></span>Americas</button>
<button type="button" class="nw-chip nw-chip-soft nw-chip-secondary" aria-pressed="true">Soft secondary</button>
<button type="button" class="nw-chip nw-chip-outline nw-chip-success" aria-pressed="true">Outline success</button>
<button type="button" class="nw-chip" disabled>Disabled</button>
</div>
<div class="nw-cluster">
<label class="nw-chip"><input type="checkbox" checked /> Label chip with a checkbox</label>
<span class="nw-chip nw-chip-sm">hel-01 <button type="button" class="nw-chip-remove" aria-label="Remove hel-01"></button></span>
<span class="nw-chip nw-chip-sm">ams-03 <button type="button" class="nw-chip-remove" aria-label="Remove ams-03"></button></span>
</div>
Class / selector Effect
nw-chip The chip. Interactive on <a>, <button>, <label>, [role="button"] or anything with a tabindex.
nw-chip-solid (default), -soft, -outline How the selected state is painted.
nw-chip-primary … -danger Intent of the selected state.
nw-chip-xs, -sm, -md, -lg Sizes.
nw-chip-check An indicator slot: an empty ring at rest, a check when selected. The slot exists in both states, so the chip keeps its width.
nw-chip-remove A remove button drawn as a cross. Give it an aria-label.
nw-chip-disabled, :disabled, [aria-disabled="true"] Disabled chip, also when its inner input is disabled.
Contact

Outage reports go here.

Enter a valid email address.

<fieldset class="nw-field-group">
<legend class="nw-field-legend">Contact</legend>
<div class="nw-field nw-field-sm">
<label class="nw-label nw-label-sm nw-label-required" for="f-mail">Email</label>
<input class="nw-input nw-input-sm" id="f-mail" type="email" autocomplete="email" required aria-describedby="f-mail-hint" />
<p class="nw-field-hint" id="f-mail-hint">Outage reports go here.</p>
<p class="nw-field-error">Enter a valid email address.</p>
</div>
<label class="nw-choice"><input class="nw-checkbox" type="checkbox" checked /> Weekly digest</label>
</fieldset>
Class / selector Effect
nw-field A column of label, control, hint and error. Invalid when a descendant has aria-invalid="true", or with nw-field-invalid.
nw-field-sm, -md, -lg Gap and type of the parts.
nw-field-invalid Forces the invalid look: the label turns danger and the error shows.
nw-field-disabled, :has(:disabled) Mutes the label and the hint of a disabled control.
nw-label The label. Wraps a checkbox, radio or switch and aligns it to the first text line.
nw-label-sm, -md, -lg Label sizes.
nw-label-text A text column inside a wrapping label, so a hint sits under the label text.
nw-label-required Appends a danger asterisk. Also set required on the control.
nw-choice A compact inline label for a choice control, at least 24px tall.
nw-field-hint Supporting text; reference it with aria-describedby.
nw-field-error Error text. Inside a field it shows only while the field is invalid; outside one it always shows.
nw-field-group, nw-field-legend A borderless <fieldset> of related fields and its legend.

The controls need no script. The demos use one delegated script for the two things HTML does not do on its own: the indeterminate checkbox state, which only exists as a DOM property (data-indeterminate in the demo), and the slider fill (--_slider-value, mirrored into an <output for>).

native-behaviors.js
// Native behaviors for the plain-HTML component demos. The nw-* classes need none of this; it only
// wires the platform features and the documented state attributes the markup relies on.
export function bindNativeBehaviors() {
document.addEventListener('click', (event) => {
const target = event.target
if (!(target instanceof Element)) return
// [data-open="#id"] opens a modal <dialog>; [data-close] closes the dialog it sits in.
const opener = target.closest('[data-open]')
if (opener) {
const dialog = document.querySelector(opener.getAttribute('data-open'))
if (dialog instanceof HTMLDialogElement && !dialog.open) dialog.showModal()
return
}
const closer = target.closest('[data-close]')
if (closer) {
closer.closest('dialog')?.close()
return
}
// [data-toggle="#id"] flips aria-expanded on the trigger and data-state on the target, the
// contract of the navbar collapse region and of collapsible sidenav groups.
const toggle = target.closest('[data-toggle]')
if (toggle) {
const region = document.querySelector(toggle.getAttribute('data-toggle'))
const open = toggle.getAttribute('aria-expanded') !== 'true'
toggle.setAttribute('aria-expanded', String(open))
region?.setAttribute('data-state', open ? 'open' : 'closed')
return
}
// [data-toast="#template"] stamps the template's toast into the region that holds the template;
// [data-dismiss] plays the toast's exit (data-state="closed") and removes it once it ends.
const notifier = target.closest('[data-toast]')
if (notifier) {
const template = document.querySelector(notifier.getAttribute('data-toast'))
if (template instanceof HTMLTemplateElement) {
template.parentElement?.append(template.content.cloneNode(true))
}
return
}
const toast = target.closest('[data-dismiss]')?.closest('.nw-toast')
if (toast) {
toast.setAttribute('data-state', 'closed')
Promise.all(toast.getAnimations().map((animation) => animation.finished)).then(() =>
toast.remove(),
)
}
})
// Range inputs: WebKit and Blink have no progress pseudo-element, so the fill reads
// --_slider-value. An <output for="id"> mirrors the value.
const paintSlider = (slider) => {
const min = Number(slider.min || 0)
const max = Number(slider.max || 100)
const percent = ((Number(slider.value) - min) / (max - min)) * 100
slider.style.setProperty('--_slider-value', `${percent}%`)
for (const output of document.querySelectorAll('output')) {
if (output.htmlFor.contains(slider.id)) output.value = slider.value
}
}
for (const slider of document.querySelectorAll('input.nw-slider')) paintSlider(slider)
document.addEventListener('input', (event) => {
if (event.target instanceof HTMLInputElement && event.target.matches('.nw-slider'))
paintSlider(event.target)
})
// Tab lists: click and arrow keys move selection (roving tabindex), Home and End jump.
for (const tabs of document.querySelectorAll('[data-tabs]')) {
const list = tabs.querySelector('[role="tablist"]')
if (!list) continue
const vertical = list.getAttribute('aria-orientation') === 'vertical'
const enabledTabs = () => [...list.querySelectorAll('[role="tab"]:not(:disabled)')]
const select = (tab, focus) => {
for (const item of list.querySelectorAll('[role="tab"]')) {
const selected = item === tab
item.setAttribute('aria-selected', String(selected))
item.tabIndex = selected ? 0 : -1
const panel = document.getElementById(item.getAttribute('aria-controls'))
if (panel) panel.hidden = !selected
}
if (focus) tab.focus()
}
list.addEventListener('click', (event) => {
const tab = event.target instanceof Element ? event.target.closest('[role="tab"]') : null
if (tab && !tab.disabled) select(tab, false)
})
list.addEventListener('keydown', (event) => {
const all = enabledTabs()
const index = all.indexOf(document.activeElement)
if (index < 0) return
const previousKey = vertical ? 'ArrowUp' : 'ArrowLeft'
const nextKey = vertical ? 'ArrowDown' : 'ArrowRight'
let next
if (event.key === nextKey) next = all[(index + 1) % all.length]
else if (event.key === previousKey) next = all[(index - 1 + all.length) % all.length]
else if (event.key === 'Home') next = all[0]
else if (event.key === 'End') next = all[all.length - 1]
if (!next) return
event.preventDefault()
select(next, true)
})
}
// The indeterminate state of a checkbox has no attribute; it is a DOM property.
for (const box of document.querySelectorAll('[data-indeterminate]')) box.indeterminate = true
}
  • Every control needs a name: a <label for>, a wrapping nw-label, or aria-label when there is no visible text.
  • When a control is invalid, set aria-invalid="true" and add the error’s id to its aria-describedby; the field shows the error and colors the label.
  • :user-invalid styles a control only after the user has interacted with it, so required fields do not start red.
  • In forced-colors mode every well, mark and thumb keeps a system-colored border.