DEV Community

Daniel Pertu
Daniel Pertu

Posted on

Our 76 public pages are built from 44 HTML elements, and they hold more SVG nodes than HTML ones

Every front end conversation about markup quality ends up at "div soup" without anyone measuring the soup. The vocabulary a site actually uses is countable, though, and so is the ratio of structural tags to generic ones. So I counted ours: every element the server sends on every public page, grouped by tag name, with the SVG namespace kept separate from the document.

The subject is Nakodo, 76 public pages served by Next 16, every page server rendered.

How it was measured

The 76 URLs come from the sitemap. Each one is fetched with curl rather than read out of a browser, because the browser profile I use for this work is signed in, and a signed-in header is not what a visitor gets. Then each document goes through Python's html.parser with a counter per tag name.

Two traps worth naming, because both of them produce confident nonsense:

  1. A React server component payload contains an escaped copy of the markup inside <script> tags. Counting tags with a regular expression therefore counts most of the page twice. html.parser switches to raw text mode inside script and style, so it does not.
  2. Elements inside <svg> share tag names with nothing in HTML except title and text, but they are a different vocabulary with different rules. Counting them together turns a drawing into markup quality. I tracked an SVG depth counter and split the two populations.

The document: 30,322 elements, 44 distinct tags

Tag Count Tag Count
a 5,184 html head title body 76 each
li 4,746 header main h1 footer 76 each
p 3,085 article 64
div 2,927 time 63
span 2,183 dl 60
meta 2,000 table thead tbody 53 each
script 1,813 input 37
link 1,354 label 36
section 657 figure figcaption 20 each
ul td 648 each caption 12
h2 576 h3 10
strong 537 form 1
th 473
tr 366
dt dd 344 each
details summary 337 each
nav 290
ol 170
button 122
aside 91

The headline number for me is the order of the top four. The most common element on this site is a link, the second is a list item, the third is a paragraph, and div is fourth at 2,927 occurrences, which is 9.7% of all elements. span is fifth. The two generic elements together are 16.9% of the document.

That is not a virtue I designed. It is what happens when the pages are generated from a content registry whose block types are "paragraph", "list", "table" and "question", so there is no opportunity to reach for a div. The divs that exist are layout wrappers in the shared shell, and they are the same ones on all 76 pages.

Eight tags appear exactly 76 times: html, head, title, body, header, main, h1, footer. One each per page, no exceptions, which is the cheapest possible proof that the page skeleton is shared and that nobody has accidentally shipped two <main> elements or a page with no heading.

The drawings: 34,175 elements, 11 distinct tags

Tag Count
path 24,832
g 5,747
svg 2,657
circle 260
ellipse 234
rect 118
defs pattern line 82 each
clipPath 80
text 1

There are more SVG nodes on this site than HTML nodes. The ratio is 1.13 to 1. Every illustration, icon, logo and the drawn landscape in the footer is inline SVG, no <img> anywhere, so the drawings are part of the document rather than a request. That decision is why path is the single most common element name of any kind on the site, at 24,832 occurrences against 5,184 links.

The one <text> element in all of that is worth a note too: there is exactly one piece of SVG text on the entire public site, and everything else that looks like lettering in a drawing is outlines.

What is not there

The more interesting half of a vocabulary census is the absent half. The HTML standard has over a hundred elements. These 76 pages use 44 of them, and the following never appear once:

  • img, picture, source, video, audio, canvas, iframe, embed, object
  • br, hr, em, i, b, small, u, s, mark, sub, sup, abbr, code, pre, blockquote, q, cite
  • h4, h5, h6, hgroup
  • select, textarea, fieldset, legend, output, progress, meter, datalist
  • tfoot, col, colgroup
  • dialog, template, slot, search, menu, address

Some of those are deliberate: no img because the drawings are inline, no iframe because nothing third party is embedded in a page, no dialog because the one modal in the product lives behind the login.

Others are a fact about the prose rather than the code. There is no em on the site at all, because the content markup supports exactly one emphasis token and it renders strong. There are 537 strong elements and zero italics. There is no code or pre, on a site that is in part documentation for a tool, which is a reasonable thing to question. And the heading scale is effectively h1 and h2: 576 h2 elements against 10 h3 elements, with nothing below. Ten h3s across 76 pages means one page type has a sub-sub-section and the other eleven do not.

Tables, questions and the single form

47 of the 76 pages carry a table, 53 tables in total because six pages have two, together 648 td and 473 th cells. 12 of those tables have a caption. The ratio of header cells to data cells is high because most of them are comparison tables with a header column as well as a header row. You can see the shape on how it works, which is one of the six pages with two, and on any alternatives page.

337 details and 337 summary elements are the FAQ blocks, one per question, spread over 66 pages. No JavaScript is involved in opening them, which is why they still work with scripting disabled.

And then the number I did not expect: there is one <form> element on the entire public site. It is on the home page, it is the email box in the hero, and it is six attributes long:

<form class="flex max-w-md flex-col gap-3 sm:flex-row" action="/login">
  <input type="hidden" name="mode" value="signup"/>
  ...
</form>
Enter fullscreen mode Exit fullscreen mode

A plain action with a hidden field, so typing an address and pressing Enter navigates to the sign-up page with the address carried over, with or without JavaScript.

The other 35 input elements on the site are in the four calculators, and not one of them is inside a form. That is correct rather than sloppy: a calculator has nothing to submit, the numbers recompute on every keystroke, and a form element would only add an implicit submission that must then be cancelled. It does mean the calculators are inert with scripting off, which the form in the hero is not. Try it on the engagement rate calculator: ten fields, no submit button anywhere, and the answer changes as you type.

Depth

The deepest element on the site is 19 levels from <html>, and it is on the home page:

html/body/div/main/section/div/div/div/div/div/div/ul/li/span/span/span/span/span/span
Enter fullscreen mode Exit fullscreen mode

Six nested spans at the bottom of that path are one animated line of text where each word, and in one case each letter group, is its own element so it can move independently. The median page bottoms out at 13 levels, and the shallowest page is 12. The div run in the middle is the layout shell: six nested wrappers for a centred, bounded, padded, gridded column.

Per page, the median is 36 distinct HTML tag names. The narrowest vocabulary is the privacy notice at 22 tags, which is what a page made of headings and paragraphs looks like. The widest is the Instagram engagement rate calculator at 40, because it has a table, a definition list, a FAQ, a figure and ten inputs on one page.

What I take from this

Three things worth acting on, and one worth leaving alone.

  1. No code element on a documentation site is a gap. Our guides talk about things like a channel handle and a search operator, and they render them as ordinary text or as strong. The content markup has two inline tokens and neither is code. That is a real limitation of a format I chose, and it shows up as an absence in this table.
  2. Ten h3s is a scale that does not exist. Either the content needs a third level consistently or those ten should be promoted or flattened. An outline that is h1, h2, h2, h2, with a surprise h3 on one page type, is harder for a reader to use than either alternative.
  3. 12 captions on 53 tables. The 41 tables without one are mostly preceded by a heading that does the same job, but a caption is the accessible version of that association and it costs one line.
  4. Leave the SVG count alone. 34,175 drawing nodes sounds like a problem and is not: they compress extremely well, they cost no requests, and they are the reason the site has no image pipeline to maintain. The census tells me where the bytes are, not that the bytes are wrong.

The whole thing is reproducible from outside the company. Fetch the 76 URLs in the sitemap, parse them with any HTML parser that honours CDATA inside script, and count. If you do the same to your own site, the number I would compare first is not the total: it is the rank of div.

Top comments (0)