HTML Concepts: Common Idioms

Published on November 2, 2021 (↻ August 26, 2022), filed under (RSS feed for all categories).

Welcome to another brief post in the “HTML Concepts” series. Today we’re going to look at common idioms: popular design patterns for which HTML doesn’t have dedicated elements, but makes suggestions.

You’re noticing that this isn’t strictly speaking a “concept”; but as this section of the specification is as commonly overlooked as it’s useful, I found it relevant to cover.

The 4 Idioms

Breadcrumbs

Despite being a popular pattern, there is no element for breadcrumbs in HTML. The spec acknowledges this by suggesting the nav element to be used for this purpose:

<nav>
  <p>You are here: <a href=/>Home</a> → <a href=/examples>Examples</a> → Example
</nav>

The spec doesn’t give examples for using lists for this purpose, but there are attempts in that direction, and using lists is probably fine. (Personally, I don’t find them suitable for breadcrumbs, but I stopped arguing against everything.)

Tag Clouds

For tag clouds the HTML spec gives the advice any experienced frontend developer would give: Use a list, and classes for popularity-related styling.

<ul>
  <li><a href=/tags/tag>tag</a>
  <li><a href=/tags/taggy>taggy</a>
  <li><a href=/tags/tagtag>tagtag</a>
  <li><a href=/tags/taggidytag>taggidytag</a>
  <!-- … -->
</ul>

You see how I omitted classes here. I did this because I’d base the decision on what markup to use on the complexity and number of levels of the tag cloud.

If there were, for example, 3–5 levels, I’d suggest to express the importance of the more popular tags through markup: For example, use strong elements for the most popular tags, em for the next most popular ones, and no markup for “normal” tags. Working with more elements (like span) and combining elements can help spawn more tag levels, and style these accordingly.

If there are many more tag levels, I might use a numbered scheme like the spec does, but I could also think of names like popular, widespread, frequent, rare, names like that, to portray tag frequencies. Sure, you probably want to prefix these following a methodology of your choice.

Conversations

For conversations, the spec describes and discusses several options. I’m an HTML minimalist and recommend the simplest option: Use paragraphs.

<p>Alice: HTML is awesome.
<p>Bob: Especially if it’s valid!
<p>Alice: Especially then.
<p>Bob: Let’s make sure we always write valid HTML!
<p>Alice: That’s what I’ve been telling you the entire time, Bob.
<!-- … -->

Footnotes

HTML has no markup for footnotes, either. Here, too, does the spec promote a few options. My favorite—and my recommendation–is to use internal links to paragraphs following the respective content (you see my own handling of footnotes in a recent article).

<p>There’s no Google homepage that uses valid HTML <a href=#fn1><sup>[1]</sup></a>.
<!-- … -->
<p id=fn1><sup>[1]</sup> except for <a href=https://www.google.cn/>google.cn</a>

❧ These are the “common idioms” in HTML, as of the end of 2021. I think this is a mildly strange section that could benefit from “TLC.” On the one hand, we could review the different cases and perhaps trim them; for example, with title coming with accessibility problems, why maintain the idea it was appropriate for footnotes? On the other hand, we could gather feedback from developers on what elements they miss in HTML, and give guidance on those.

That’s it—see you again soon, in another episode of “HTML Concepts.”

Was this useful or interesting? Share (toot) this post, become a one-time nano-sponsor, or support my work by learning with my ebooks.

About Me

Jens Oliver Meiert, on November 9, 2024.

I’m Jens (long: Jens Oliver Meiert), and I’m a frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, and I write and review books for O’Reilly and Frontend Dogma.

I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Please be critical, interpret charitably, and give feedback.)