DEV Community

Daniel Pertu
Daniel Pertu

Posted on

Our 38 pages render 402 headings and carry one hand-written id, so nothing on the site can be linked to

Notifio is a desktop app that watches rental search pages for new listings. The site that sells it is 38 URLs of mostly static text: a hub of the sites it watches, five comparison pages, five guides, and the usual pricing, help and policy pages.

I have measured a lot of things about those 38 pages. I counted every JSON-LD node on them, I counted every FAQ question, and I ran an accessibility census over the deployed HTML.

Not one of those measurements asked whether you can link to anything inside a page. This week somebody emailed asking a question that is answered in a particular paragraph of one of the guides, and I wanted to reply with a link to that paragraph. I could not, and the reason turned out to be total.

The census

I loaded all 38 URLs in Chromium and counted every id, every heading and every anchor in the rendered DOM.

headings (38 pages)              402
  h1                              38
  h2                             260
  h3                             104
headings carrying an id            0

id attributes in the whole site   39
  script#_R_  (framework)         38
  input#email (mine)               1

<section> elements               229
<section> with an id               0
<article> elements                 0

anchors                        1,091
anchors whose href has a #         0
<a name="...">                     0
Enter fullscreen mode Exit fullscreen mode

Thirty-nine id attributes across 38 pages, and 38 of those are the same <script id="_R_"> that Next.js puts in every document. The entire site has one id that a human typed, and it is this one, on the pricing page:

<label htmlFor="email" ...>
<input id="email" ... />
Enter fullscreen mode Exit fullscreen mode

It exists to be the target of the only htmlFor in the repository, not to be an address. Grepping the source agrees:

$ grep -rho 'id="[a-zA-Z-]*"' server/src | sort | uniq -c
   1 id="email"
Enter fullscreen mode Exit fullscreen mode

Sixty-four heading tags in the JSX produce 402 rendered headings, because the content pages are a map over arrays of section objects. Every section on the site is keyed by its own heading text in React, and none of them turns that text into a slug.

The fragments we do have, all 208 of them

Here is the part that made the measurement worth writing up. The site is full of URL fragments. They are all in the structured data.

ld+json script tags (38 pages)           73
@id values inside them                  209
@id values containing a #               208
distinct fragment identifiers            47
Enter fullscreen mode Exit fullscreen mode

Ranked:

 89  https://notifio.app/#organization
 43  https://cogniprep.app/about#cogniprep-ltd
 33  https://notifio.app/#software
 30  .../alerts/<site>#faq  and  .../compare/<target>#faq
  8  .../guides/<slug>#article  and  .../for/<audience>#article
  3  /alerts#sites, /compare#comparisons, /guides#articles
Enter fullscreen mode Exit fullscreen mode

A JSON-LD @id is a node identifier in a graph, not a scroll target. Using a fragment there is the correct thing to do, and I wrote about choosing one deliberately when four of my apps needed to name the same publisher without looking like a link scheme. #organization is not meant to resolve in a browser.

But it leaves the site in a funny state. Every single fragment string we publish is one that cannot be used as an address, and every section a reader might want an address for has no fragment at all. The FAQ page emits #faq thirty times, and if you paste https://notifio.app/alerts/rightmove#faq into a browser you land at the top of the page, because the #faq is a name in a graph and there is no element called that.

The dead line in our stylesheet

globals.css has this:

html {
  color-scheme: dark;
  scroll-behavior: smooth;
  overscroll-behavior-y: none;
}
Enter fullscreen mode Exit fullscreen mode

scroll-behavior: smooth animates two things: fragment navigation and scrollTo calls. The site has zero fragment targets, and the only programmatic scroll in the whole site is one scrollTop assignment inside an animated demo, which scroll-behavior does not touch. That declaration has never animated anything. It has been shipped on every page load of every one of the 38 pages for months, doing nothing, which is a good reminder that CSS does not warn you when a property has no work to do.

What it actually costs

Three things, in rising order of annoyance:

  1. Support replies. 125 FAQ questions on the site, and the only way to point at one is "scroll down to the bit about sites that need a login".
  2. The guides. The longest content page has 19 headings. A scam-avoidance guide and a documents checklist are exactly the kind of page people link to a section of, and ours are addressable only as a whole.
  3. Our own search presence. Google generates its own scroll-to-text fragments for featured snippets, so this does not block anything. But a page with named sections gives it something explicit to point at, and we give it 402 unnamed ones.

The fix, and the part of it that is easy to miss

The template already has the heading string in hand, so it is a slugify and two attributes:

{article.sections.map((section) => {
  const slug = slugify(section.heading);
  return (
    <section key={section.heading} id={slug} className="scroll-mt-20">
      <h2>
        <a href={`#${slug}`}>{section.heading}</a>
      </h2>
Enter fullscreen mode Exit fullscreen mode

The scroll-mt-20 is the part I would have forgotten. The nav on this site is fixed top-0 and the main content is pushed down by pt-14, so 56 pixels of every page are covered by a floating header. A fragment jump without a scroll margin puts the heading exactly under it, and the reader lands on the first paragraph of the section with the title invisible above them. Deep links that look broken are worse than no deep links.

Two things I am deliberately not doing:

  • No ids on the nav or footer. 532 of the site's 1,343 keyboard-reachable elements are the same 14-link footer repeated 38 times. Addressing those is meaningless.
  • No heading anchors on /terms and /privacy. They have 19 and 12 headings each, and they are the two pages where someone quoting one clause out of context is a cost rather than a convenience.

If you want to check the current state yourself, every page is public: try #anything on the end of the help page, the pricing page or any guide. All 38 of them will accept the fragment, scroll smoothly, and land you precisely at the top.

Top comments (0)