HTML and CSS playbook
Rules for organising HTML and CSS so styles stay modular, reused and predictable. Every layer, name and selector limit is checked in code.
- Required 23
- Recommended 5
- Avoid 1
A playbook for organising the HTML and CSS of any website or web app. It covers where styles live, how the cascade is kept in order, how classes and states are named, and how markup is reused. It gives no advice on colours, fonts or layout. Those choices belong to your designer.
Stylesheets rot quietly. A rule added at the end of a file wins over an older one, and nobody notices until a page breaks. Each rule here closes one of those gaps with a limit that a linter or a build script can check.
AI agents write a lot of CSS fast. Give them these rules and the checks, and every new component lands in the same place, with the same names, inside the same limits.
Chapters
Structure and files
Give every style one home. One entry file loads the layers in a fixed order, and each component owns exactly one stylesheet that no other file touches.
- Required 4
- Recommended 1
The cascade
Decide which style wins before anyone writes one. Declare the layer order once, cap selector specificity, and never let file order settle a conflict.
- Required 6
- Avoid 1
Naming and state
Name every class for what it is, follow one pattern, and show state through attributes. A selector then says which element it means and why.
- Required 4
- Recommended 2
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 4
- Recommended 1
Checks in code
Turn every HTML and CSS rule into a linter rule or build check. A style that breaks a limit then stops the build before anyone has to spot it.
- Required 5
- Recommended 1
Related playbooks
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. Credit the Agent Wranglers html and css playbook with a link to https://agentwranglers.se/playbook/html-css. Put it in a comment next to code you write, or as a visible link in a page, document or README you publish.