Skip to content
Norn
Menu

norn-field

A labeled text control: a <label> and an <input>, <textarea>, or <select>, with an optional hint and error message under it. The control takes the control height, a strong edge, and a hover layer; readonly draws a dashed edge, disabled a raised fill. After the visitor touches it, an invalid control (:user-invalid, or aria-invalid="true") takes the danger edge, as does any control with an error in its slot. A script points the control's aria-describedby at the hint and the error; without it, give them an id and link them yourself. Mark a required field with the required attribute, and a visible asterisk in the label inside aria-hidden="true". Group checkboxes and radios with norn-choice.

<norn-field> a component, from @allons-y/webc-patterns

Examples

Color scheme
Width

Open on its own

Source
<norn-field>
	<label for="field-name">Name</label>
	<input id="field-name" type="text" autocomplete="name" />
</norn-field>
Color scheme
Width

Open on its own

Source
<norn-field>
	<template slot="hint" webc:nokeep><span slot="hint">Lowercase letters, numbers, and dashes.</span></template>
	<label for="field-handle">Handle <span aria-hidden="true">*</span></label>
	<input id="field-handle" type="text" required />
</norn-field>
Color scheme
Width

Open on its own

Source
<norn-field>
	<template slot="error" webc:nokeep><span slot="error">Add the part after the @.</span></template>
	<label for="field-email">Email</label>
	<input id="field-email" type="email" value="cassondra" aria-invalid="true" />
</norn-field>
Color scheme
Width

Open on its own

Source
<norn-field>
<label for="field-message">Message</label>
<textarea id="field-message"></textarea>
</norn-field>
Color scheme
Width

Open on its own

Source
<norn-field>
	<label for="field-topic">Topic</label>
	<select id="field-topic"><option>Speaking</option><option>Consulting</option><option>Something else</option></select>
</norn-field>
Color scheme
Width

Open on its own

Source
<norn-field>
	<label for="field-id">Order number</label>
	<input id="field-id" type="text" value="A-1024" readonly />
</norn-field>
Color scheme
Width

Open on its own

Source
<form action="#" method="post" style="display: grid; gap: 1.5rem; max-inline-size: 32rem;">
	<norn-field>
		<label for="contact-name">Name <span aria-hidden="true">*</span></label>
		<input id="contact-name" name="name" type="text" autocomplete="name" required />
	</norn-field>
	<norn-field>
		<label for="contact-email">Email <span aria-hidden="true">*</span></label>
		<input id="contact-email" name="email" type="email" autocomplete="email" required aria-invalid="true" value="cassondra" />
		<span slot="error">Add the part after the @.</span>
	</norn-field>
	<norn-field>
		<label for="contact-topic">Topic</label>
		<select id="contact-topic" name="topic">
			<option>Speaking</option>
			<option>Consulting</option>
			<option>Something else</option>
		</select>
	</norn-field>
	<norn-field>
		<label for="contact-message">Message</label>
		<textarea id="contact-message" name="message"></textarea>
		<span slot="hint">Links are fine; attachments aren't.</span>
	</norn-field>
	<norn-choice>
		<span slot="legend">Reply by</span>
		<label><input type="radio" name="reply" value="email" checked /> Email</label>
		<label><input type="radio" name="reply" value="none" /> No reply needed</label>
	</norn-choice>
	<norn-choice>
		<span slot="legend">Extras</span>
		<label><input type="checkbox" name="newsletter" value="yes" /> Send me the newsletter</label>
	</norn-choice>
	<div>
		<button type="submit">Send message</button>
	</div>
</form>
Color scheme
Width

Open on its own

Source
<div style="display: grid; gap: 1.5rem; max-inline-size: 32rem;">
	<norn-field>
		<label for="state-default">Default</label>
		<input id="state-default" type="text" />
	</norn-field>
	<norn-field>
		<label for="state-readonly">Read-only</label>
		<input id="state-readonly" type="text" value="A-1024" readonly />
	</norn-field>
	<norn-field>
		<label for="state-disabled">Disabled</label>
		<input id="state-disabled" type="text" value="Not now" disabled />
	</norn-field>
	<norn-field>
		<label for="state-invalid">Invalid</label>
		<input id="state-invalid" type="url" value="example" aria-invalid="true" />
		<span slot="hint">The whole address, from https://.</span>
		<span slot="error">Add the scheme, such as https://.</span>
	</norn-field>
</div>

Slots

NameDescription
default A <label> and the control it names: an <input>, a <textarea>, or a <select>.
hint Help shown under the control, such as <span slot="hint">As on your ID</span>.
error The error message, without its prefix, such as <span slot="error">Add the part after the @.</span>. Hidden while empty; filled, it also marks the control.
error-prefix The word read before the error message.

Tokens

The global tokens from tokens.json the component reads. Set one in a project's tokens.css to change it everywhere.

Type a value to try it in every example above. Reset puts the default back.

Token Type Default Override
--norn-ui-accentThe brand color, shared by every component. <color> #2346d4
--norn-ui-border-colorHairline color. <color> light-dark(#d3d8e2, #2d323e)
--norn-ui-border-strongEdge of a control, such as a field. At least 3:1 on the page surface, which WCAG 1.4.11 asks of a control's boundary. <color> light-dark(#7a8194, #6f7789)
--norn-ui-border-radiusCorner radius. <length> 6px
--norn-ui-state-hoverShare of the text color mixed into the background while the pointer is over a control. <percentage> 8%
--norn-ui-motion-durationLength of a state change, such as a hover layer. <time> 150ms
--norn-ui-motion-easingEasing for every transition. <easing-function> cubic-bezier(0.2, 0, 0, 1)
--norn-ui-control-heightHeight of a button, field, or tab. A component raises it to 2.75rem for a coarse pointer. <length> 2.25rem
--norn-surface-basePage surface. Light and dark values. <color> light-dark(#ffffff, #101216)
--norn-surface-raisedRaised surface. <color> light-dark(hsl(40, 14%, 96%), #242932)
--norn-text-baseText color. <color> light-dark(#16181d, #eceef3)
--norn-text-mutedSecondary text color. <color> light-dark(#4b5160, #a4abba)
--norn-text-accentThe accent for text and links: darkened in light mode, lightened in dark mode. The lightness caps keep any accent at 4.5:1 or better. <color> light-dark(oklch(from color-mix(in oklch, var(--norn-ui-accent, #2346d4) 82%, black) min(l, 0.5) c h), oklch(from color-mix(in oklch, var(--norn-ui-accent, #2346d4) 55%, white) max(l, 0.72) c h))
--norn-font-size-sSmall text: captions, code, navigation, and notes. <length> 0.875rem
--norn-space-2xsSmallest spacing step. <length> 0.25rem
--norn-space-sSmall spacing step. <length> 0.75rem
--norn-status-dangerDanger. The color of a caution and an error. <color> light-dark(#b42318, #ff8a80)