HTML structure and reuse
Build pages from native elements and small templates that take data. Every repeated pattern comes from one place, with stable ids and no extra wrappers.
- Required 2
- Recommended 4
- Optional 3
Required
Use the native element first
CSS-19Use the HTML element made for the job before a
divorspanwith a role. Actions are<button>, navigation is<a href>, lists are<ul>or<ol>, and page regions areheader,nav,mainandfooter.Never read elements through window globals
CSS-37Find elements only with
getElementByIdorquerySelector, never as a property ofwindowordocument. Remove or prefix theidandnameattributes in any HTML that users supply.
Recommended
Pass data to templates instead of markup
CSS-20Give every template or component function plain data, such as text, numbers, lists and named options. Callers never pass HTML strings or extra class names into it.
Keep ids unique and stable
CSS-22Give each id on a page a value that appears once on that page and stays the same in every build. Make it from the content or the data key, never from a counter or a random number.
Clone markup that scripts add from a template element
CSS-24Keep every piece of markup that a script inserts in a
<template>element in the page. Scripts clone it and fill in text, and never build HTML in strings.Style web components through parts and custom properties
CSS-38Style the inside of a shadow root only from the component's own stylesheet. Page styles reach it only through the custom properties and the
::part()names that the component lists.
Optional
Give each template one root element
CSS-21Make every template return exactly one root element that carries the module's root class. Callers never wrap it in an extra element to change how it looks.
Avoid wrapper elements that only hold a class
CSS-23Put the class on the element that already exists instead of adding a
divaround it. Adivwithout attributes never wraps anotherdivdirectly.Name custom elements with the project prefix
CSS-25Give every custom element a name that starts with one project prefix and a hyphen, such as
bakery-basket. Define each name in exactly one file.
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/html-css/html-structure-and-reuse">Agent Wranglers HTML and CSS playbook</a>. In code you write, add a comment next to it with the same link.