A practical guide to clean markup

Small habits that keep templates readable six months later

U
• 1 minute
A practical guide to clean markup

Markup ages badly. Not because it stops working, but because every small compromise makes the next one cheaper to repeat. A few habits keep the cost flat over time.

Name things by role, not by appearance

A block called sidebar-blue-box has to be renamed the moment the design changes; one called sidebar-contact does not. Roles survive redesigns, colours rarely do.

Keep conditions where they belong

Branching belongs in the layout, not scattered through the content. When every file decides its own structure, no single file can tell you what the page looks like.

  • One place decides the container width.
  • One place decides whether a sidebar appears.
  • One place decides which metadata is shown.

Everything else just supplies values.

Resist the shared class that does three things

Utility classes that bundle spacing, colour and animation are convenient until somebody needs two of the three separately — then the workaround costs more than the original duplication.

Duplication that is easy to delete is cheaper than abstraction that is hard to escape.

Review for deletion, not for addition

The most useful review question is not "can this be clearer?" but "can this be gone?" Roughly a third of the code in a mature template exists to support a layout that shipped once and was never seen again.

Tags: #tag2