• Stars
    star
    114
  • Rank 306,282 (Top 7 %)
  • Language
    HTML
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A script to test the heading outline of a document

Document outline audit

This small script analyses the heading outline of the document (or given container), and report possible errors. It can be dropped in the DevTools directly, put into a bookmarklet or integrated to a testing suite for example. It’s pretty much up to you.

Bookmarklet

Unfortunately, GitHub prevents JS links in README, so you’ll have to make the bookmarklet yourself. Here is the code:

(function(e,n,t){n=e.body,t=e.createElement('script'),t.src='https://cdn.rawgit.com/edenspiekermann/outline-audit/master/index.js',t.async=!0,t.onload=function(){new Outline().warn()},n.appendChild(t)}(document));

And wrapped with a link already:

<a href="javascript:(function(e,n,t){n=e.body,t=e.createElement('script'),t.src='https://cdn.rawgit.com/edenspiekermann/outline-audit/master/index.js',t.async=!0,t.onload=function(){new Outline().warn()},n.appendChild(t)}(document));">Audit document outline</a>

DevTools snippet

Go in Sources tab, then Snippets sub-tab in the left panel. Right click, and click New. Then paste the script, and add new Outline().warn() at the very end. Save, and you should be able to run it whenever you want.

DevTools snippet for Outline Audit

Note: this disconnects you from the source. You won’t get updates.

Basic usage

Display warnings in the console:

var outline = new Outline()
outline.warn()

Example usage from DevTools

Get an array of warnings:

var outline = new Outline()
outline.audit()

Get the outline itself:

var outline = new Outline()
outline.parse()

About the document outline

The document outline is the theoretical schema constructed from the structure of a document (such as a web page), mostly based on headings. It matters because assistive technologies like screen readers heavily rely on this to give context and help navigation. It also matters for search engines, so they can locate and index meaningful content first.

With HTML5, we got a set of new “sectioning elements”, such as <header>, <footer>, <section>, <aside>, <article> and so on. The theory (a.k.a the specification) says that inside one of these elements, the document outline is being resetted to create a sub-outline. The same way nested ordered list have their own counter and create sub-lists.

However, that is the theory. In practice, unfortunately, it is dramatically different. As of today, there is not a single browser or user assistive technology that applies this. It means that right now, regarding document outline (exclusively), these elements are no different than <div>. And that means that if you rely on these sectioning elements to put <h1> everywhere, you end up with a flat document outline composed exclusively of <h1>, which hurts accessibility and possibly SEO.

If you as a developer want to provide a meaningful document structure, use the <h1>–<h6> elements to express document structure. DO NOT rely upon the HTML5 document outline. By all means use the HTML5 section elements, but do not rely upon them to convey a meaningful structure. If at some point in the future the HTML5 document outline ceases to be a fiction, you will be covered as the use of h1–h6 is backwards compatible. — Steve Faulkner

To avoid these issues, we can make our heading structure consistent and meaningful. Basically, it does not matter what kind of container we use, the heading level must be meaningful in regard to the previous heading. If it is a sort of sub-section, go down one level in the heading structure. If it is an unrelated section, have the same kind of heading as before. When checking the page, we should have a logical heading structure (which also mean never skipping a heading level). It’s actually what recommends the HTML5 specification:

Sections may contain headings of any rank, and authors are strongly encouraged to use headings of the appropriate rank for the section’s nesting level. — HTML 5.1 - Headings and sections

Last thing to point out on this topic: the theory is so far away from the current state of things that the spec authors decided to review the whole thing to design something that will actually make sense and get implemented. More to come in the next few months.

More on the topic in this outstanding article about the document outline by Adrian Roselli.

More Repositories

1

sprite.sh

A Bash script to build a SVG sprite from a folder of SVG files (typically icons).
JavaScript
327
star
2

a11y-toggle

A tiny script for accessible content toggles.
HTML
304
star
3

iframify

Replace a node with an iframe version of itself
JavaScript
212
star
4

minwidth-relocate

JavaScript
125
star
5

faster-react-tabs

JavaScript
48
star
6

gatsby-source-shopify-storefront

Gatsby source plugin for building websites using product data from the Shopify Storefront API
JavaScript
31
star
7

craft3-heroku-starterkit

This is a starter kit for Craft3 which helps you to install the CMS on Heroku
JavaScript
18
star
8

transync

A npm module to synchronise translation files.
JavaScript
10
star
9

nanoc-html5-template

A nanoc template using Sass, Haml and Compass Html5 Boilerplate
JavaScript
10
star
10

espi-devblog

Edenspiekermann Developer Blog
HTML
9
star
11

craft-jwt-auth

Enable authentication to Craft through the use of Javascript Web Tokens (JWT)
PHP
5
star
12

espi-eslint-config

ESLint configuration
JavaScript
3
star
13

espi-dni

PostBot for DNI Project
Elixir
3
star
14

themer

A Tumblr theme parser for local development.
PHP
3
star
15

edenspiekermann-storybook-starter

Boilerplate repo for React-based component libraries
CSS
2
star
16

bright

JavaScript
2
star
17

site-status

Keep track of website development status
Ruby
2
star
18

static-importer

JavaScript
1
star
19

card-builder-docs

Docs to assist with the implementation of Card Builder (http://cards.edenspiekermann.com/)
1
star
20

signals

Signals from content
JavaScript
1
star
21

react-project-examples

Example projects to test styleguide usage
JavaScript
1
star
22

kupong_integration

Ruby
1
star