HTML Concepts: Common Idioms
Published on NovĀ 2, 2021 (updated AugĀ 26, 2022), filed under development, html, semantics (feed). (Share this on Mastodon orĀ Bluesky?)
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.ā
About Me
Iām Jens (long: Jens Oliver Meiert), and Iām a web developer, manager, and author. Iāve been working as a technical lead and engineering manager for companies youāve never heard of and companies you use every day, Iām an occasional contributor to web standards (like HTML, CSS, WCAG), 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. (I value you being critical, interpreting charitably, and giving feedback.)