Skip to content

Native Patterns

NightCSS has no components. Native HTML now covers most of what framework widgets used to provide, and NightCSS styles the pieces to match. These patterns replace the usual <Modal>, <Tooltip>, and <Accordion> components with a few lines of plain HTML and CSS. Everything on this page is live — use the examples.

Delete project?

This cannot be undone.

<button type="button" data-open-dialog>Open dialog</button>
<dialog class="rounded-lg border" style="padding: 0; max-width: 24rem">
<form method="dialog" class="stack" style="padding: 1rem">
<h2>Delete project?</h2>
<p class="text-muted">This cannot be undone.</p>
<div class="flex justify-end gap-2">
<button value="cancel">Cancel</button>
<button value="confirm" class="bg-accent text-accent-contrast rounded-md">Delete</button>
</div>
</form>
</dialog>
const dialog = document.querySelector('dialog');
document.querySelector('[data-open-dialog]').addEventListener('click', () => dialog.showModal());

showModal() handles focus trapping, the backdrop, and Esc for you. Style the backdrop with ::backdrop in your own CSS.

popover — tooltips and menus with zero JavaScript

Section titled “popover — tooltips and menus with zero JavaScript”

The popover attribute gives a dismissible, top-layer popover with no JS. Open this one, then click anywhere outside it or press Esc:

<button popovertarget="menu">Actions</button>
<ul popover id="menu" class="rounded-lg border" style="padding: 0.5rem; list-style: none">
<li><button>Rename</button></li>
<li><button>Duplicate</button></li>
<li><button>Delete</button></li>
</ul>

Light-dismiss and Esc come built in. Position the popover with anchor positioning (position-anchor, anchor()) or a wrapper in your own CSS.

How does theming work?

Override any –nc-* token on :root.

<details class="border rounded-md">
<summary>How does theming work?</summary>
<p class="text-muted">Override any <code>--nc-*</code> token on <code>:root</code>.</p>
</details>

The <summary> marker can be styled with summary::marker, and details[open] targets the expanded state.

<label for="plan">Plan</label>
<select id="plan">
<option value="free">Free</option>
<option value="pro">Pro</option>
<option value="team">Team</option>
</select>

NightCSS styles the control with the surface, border, and radius tokens. For a fully custom look, keep the native <select> and style its wrapper — the native dropdown stays keyboard- and touch-accessible.

:has() lets a container react to a descendant’s state. Check the box:

/* A form with a checked checkbox. */
.field:has(input:invalid) {
--nc-accent: oklch(60% 0.2 25);
}
/* A card that contains an image. */
.card:has(img) {
padding: 0;
}

It also powers sibling styling without a framework:

label:has(+ input:focus) {
color: var(--nc-accent);
}

field-sizing — forms that grow with their content

Section titled “field-sizing — forms that grow with their content”

NightCSS sets field-sizing: content on textareas, so they expand as you type instead of showing an internal scrollbar:

<textarea rows="1" placeholder="Type and watch it grow…"></textarea>