Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html data-lightMode=auto>

<body>
  <main aria-label=Content>
    <header aria-label="Content header">
      <div>
        <h1>Highlighting landmarks and headings</h1>

        <p>A bookmarklet to help with WCAG 2.1: 1.3.1 - Info and Relationships - Identifies and highlights each landmark or heading.</p>
      </div>
    </header>

    <div class=test-elements>

      <section>
        <header>header</header>
        <div role=banner>div[role=banner]</div>
        
        <aside>aside</aside>
        <div role=complementary>div[role=complementary]</div>

        <footer>footer</footer>
        <div role=contentinfo>div[role=contentinfo]</div>

        <form>form</form>
        <div role=form>div[role=form]</div>
        
        <div role=search>div[role=search]</div>
        
        <main>main</main>
        <div role=main>div[role=main]</div>
        
        <nav>nav</nav>
        <div role=navigation>div[role=navigation]</div>
        
        <section>section</section>
        <div role=region>div[role=region]</div>
      </section>

      <section>
        <h1>h1</h1>
        <div role=heading aria-level=1>div[role=heading][aria-level=1]</div>
        <h2>h2</h2>
        <div role=heading>div[role=heading]</div>
        <div role=heading aria-level=2>div[role=heading][aria-level=2]</div>
        <h3>h3</h3>
        <div role=heading aria-level=3>div[role=heading][aria-level=3]</div>
        <h4>h4</h4>
        <div role=heading aria-level=4>div[role=heading][aria-level=4]</div>
        <h5>h5</h5>
        <div role=heading aria-level=5>div[role=heading][aria-level=5]</div>
        <h6>h6</h6>
        <div role=heading aria-level=6>div[role=heading][aria-level=6]</div>

        <div role=heading aria-level=7>div[role=heading][aria-level=7]</div>
        <div role=heading aria-level=8>div[role=heading][aria-level=8]</div>
      </section>
    </div>

    <div>
      
      <h2>Bookmarklet</h2>
      
      <p>Drag this link into your bookmark bar: <a href="javascript:const outliner=(e=>{'use strict';const o={header:'#eb0000',banner:'#eb0000',aside:'#8a7500',complementary:'#8a7500',footer:'#268500',contentinfo:'#268500',form:'#062',search:'#062',main:'#0076d1',nav:'#8a7500',navigation:'#8a7500',section:'#8352ff',region:'#8352ff',h1:'#008a27','heading 1':'#008a27',h2:'#007cad','heading 2':'#007cad',h3:'#8352ff','heading 3':'#8352ff',h4:'#db009d','heading 4':'#db009d',h5:'#d63d00','heading 5':'#d63d00',h6:'#5b8000','heading 6':'#5b8000'},t=(e,o,t)=>{'static'!==getComputedStyle(e).position||e.classList.add('-js-overlay');const r=((e,o)=>{const t=document.createElement(e);return t.className=o,t})('span','-js-overlay-border');r.style.setProperty('--overlay-bg-color',t),r.style.setProperty('--overlay-color','#fff'),r.style.setProperty('--overlay-text','\''+o+'\''),e.appendChild(r)};(e=>{const r=(e,t,r)=>t in o?t:r in o?r:t,a=document.querySelectorAll(':is(header,nav,main,aside,footer,section,form,[role=banner],[role=navigation],[role=main],[role=complementary],[role=contentinfo],[role=form],[role=search],[role=region])');for(const e of a){const a=e.getAttribute('role'),n=r(0,e.tagName.toLowerCase(),a);t(e,n,o[n])}})(),(e=>{const r=(e,t,r)=>t in o?t:('heading'===r&&(t=`heading ${e.getAttribute('aria-level')||'2'}`),t),a=document.querySelectorAll(':is(h1,h2,h3,h4,h5,h6,[role=heading])');for(const e of a){const a=e.getAttribute('role'),n=r(e,e.tagName.toLowerCase(),a);t(e,n,o[n]||'#c00')}})(),(e=>{const o=document.createElement('style');o.id='a11y-overlay',o.textContent='.-js-overlay{position:relative}.-js-overlay-border{position:absolute;inset:0;outline:2px solid var(--overlay-bg-color,#000);outline-offset:-2px;pointer-events:none;width:100%}.-js-overlay-border::after{all:unset;background-color:var(--overlay-bg-color,#000);content:var(--overlay-text, \'???\');position:absolute;top:0;right:0;color:var(--overlay-color,#fff);font-size:12px;font-weight:400;letter-spacing:.03em;text-shadow:0 0 1px #000;padding:2px 4px 1px}',document.head.appendChild(o)})()})();">Highlight landmarks and headings</a></p>
      <p>Or, create a bookmark, and copy the JavaScript into its URL.</p>
      
      <details>
        <summary>The JavaScript</summary>
        <figure>
          <figcaption id=bookmrklet>Copy into a bookmarks URL:</figcaption>
          <pre class="language-css" contenteditable spellcheck="false" role="textbox" aria-multiline="true" aria-labelledby="bookmrklet"><code>javascript:const outliner=(e=&gt;{'use strict';const o={header:'#eb0000',banner:'#eb0000',aside:'#8a7500',complementary:'#8a7500',footer:'#268500',contentinfo:'#268500',form:'#062',search:'#062',main:'#0076d1',nav:'#8a7500',navigation:'#8a7500',section:'#8352ff',region:'#8352ff',h1:'#008a27','heading 1':'#008a27',h2:'#007cad','heading 2':'#007cad',h3:'#8352ff','heading 3':'#8352ff',h4:'#db009d','heading 4':'#db009d',h5:'#d63d00','heading 5':'#d63d00',h6:'#5b8000','heading 6':'#5b8000'},t=(e,o,t)=&gt;{'static'!==getComputedStyle(e).position||e.classList.add('-js-overlay');const r=((e,o)=&gt;{const t=document.createElement(e);return t.className=o,t})('span','-js-overlay-border');r.style.setProperty('--overlay-bg-color',t),r.style.setProperty('--overlay-color','#fff'),r.style.setProperty('--overlay-text','\''+o+'\''),e.appendChild(r)};(e=&gt;{const r=(e,t,r)=&gt;t in o?t:r in o?r:t,a=document.querySelectorAll(':is(header,nav,main,aside,footer,section,form,[role=banner],[role=navigation],[role=main],[role=complementary],[role=contentinfo],[role=form],[role=search],[role=region])');for(const e of a){const a=e.getAttribute('role'),n=r(0,e.tagName.toLowerCase(),a);t(e,n,o[n])}})(),(e=&gt;{const r=(e,t,r)=&gt;t in o?t:('heading'===r&amp;&amp;(t=`heading ${e.getAttribute('aria-level')||'2'}`),t),a=document.querySelectorAll(':is(h1,h2,h3,h4,h5,h6,[role=heading])');for(const e of a){const a=e.getAttribute('role'),n=r(e,e.tagName.toLowerCase(),a);t(e,n,o[n]||'#c00')}})(),(e=&gt;{const o=document.createElement('style');o.id='a11y-overlay',o.textContent='.-js-overlay{position:relative}.-js-overlay-border{position:absolute;inset:0;outline:2px solid var(--overlay-bg-color,#000);outline-offset:-2px;pointer-events:none;width:100%}.-js-overlay-border::after{all:unset;background-color:var(--overlay-bg-color,#000);content:var(--overlay-text, \'???\');position:absolute;top:0;right:0;color:var(--overlay-color,#fff);font-size:12px;font-weight:400;letter-spacing:.03em;text-shadow:0 0 1px #000;padding:2px 4px 1px}',document.head.appendChild(o)})()})();
</code></pre>
        </figure>
      </details>
      
      <p>The bookmarklet is completely self-contained, does not reference other URLs, and can be used safely on pages that have strict content security policies.</p>

      
      <h2>1.3.1 - Info and Relationships</h2>
      
      <p>Information, structure, and relationships conveyed through presentation can be programmatically determined or are available in text.</p>
      <p></p>
      <ul>
        <li>Use landmarks: HTML elements: nav, main, header, footer etc. Or, use Aria roles: navigation, main, banner, contentinfo, etc.</li>
        <li>Label landmarks (<code>aria-label</code> or <code>aria-labelledby</code>) if there is more than one with the same role on the page.</li>
        <li>Use HTML headings <code>h1</code> to <code>h6</code> wherever possible, if not then use <code>role="heading"</code> <code>aria-level="[1, 2, 3, 4, 5, 6, 7, &hellip;]"</code></li>
        <li>Use <code>fieldset</code> and <code>legend</code> or <code>role="group"</code> <code>aria-labelledby="heading id"</code>. Add <code>aria-describedby="description id"</code> if more detail required.</li>
        <li>Ensure every <code>input</code> has a <code>label</code> to describe the input/control</li>
        <li>Ensure tables are used for data layout only, and each has a <code>caption</code> and scoped table headings (th).</li>
        <li>Use lists where appropriate.</li>
        <li>Use buttons to do something, and links to go somewhere.</li>
      </ul>
      <p><a href="https://www.w3.org/WAI/WCAG21/Understanding/info-and-relationships.html" target=_blank>Understanding 1.3.1</a></p>
    </figure>

  </main>
</body>

</html>
              
            
!

CSS

              
                body {
  font-family: sans-serif;
  line-height: 1.5;
}
.test-elements {
}
.test-elements > section {
  padding: .5rem 1rem;
}
/* Switch off highlighting on page elements - for readability */
body > main > span,
body > main > div > h2 > span,
main > header > span,
main > header > div > h1 > span,
.test-elements > section > span {
  display: none;
}
section > header {
  border: none;
}
.test-elements > section > * {
  display: block;
  font-size: 1rem;
  font-weight: normal;
  margin: .5rem 0 0;
  padding: .125rem 0 0 .5rem;
}
.test-elements :is(aside,footer,form,main,nav,section,[role=search]),
.test-elements :is(h1,h2,h3,h4,h5,h6,[role="heading"][aria-level="7"]) {
  margin-top: 1.5rem;
}
.test-elements :first-child {
  margin-top: 0;
}


/* Highlighting */

/* Disabled here but added through JS:

.-js-overlay {
  position: relative;
}
.-js-overlay-border {
  position: absolute;
  inset: 0;
  outline: 2px solid var(--overlay-bg-color, #000);
  outline-offset: -2px;
  pointer-events: none;
  width: 100%;
}
.-js-overlay-border::after {
  all: unset;
  background-color: var(--overlay-bg-color, #000);
  content: var(--overlay-text, '???');
  position: absolute;
  top: 0;
  right: 0;
  color: var(--overlay-color, #fff);
  font-size: 12px;
  font-weight: normal;
  letter-spacing: .03em;
  text-shadow: 0 0 1px #000;
  padding: 2px 4px 1px;
}

*/

              
            
!

JS

              
                console.clear();

const outliner = (_ => {
  'use strict';

  // Colours generated by :https://codepen.io/2kool2/pen/ExQKJZa
  // Set of 7 and 6 colours with different offsets */

  const colorText = "#fff";

  const colors = {
    'header' : '#eb0000',
    'banner' : '#eb0000',

    'aside' : '#8a7500',
    'complementary' : '#8a7500',

    'footer' : '#268500',
    'contentinfo' : '#268500',

    'form' : '#062',
    'search' : '#040',

    'main' : '#0076d1',

    'nav' : '#8a7500',
    'navigation' : '#8a7500',

    'section' : '#8352ff',
    'region' : '#8352ff',

    'h1' : '#008a27',
    'heading 1' : '#008a27',

    'h2' : '#007cad',
    'heading 2' : '#007cad',

    'h3' : '#8352ff',
    'heading 3' : '#8352ff',

    'h4' : '#db009d',
    'heading 4' : '#db009d',

    'h5' : '#d63d00',
    'heading 5' : '#d63d00',

    'h6' : '#5b8000',
    'heading 6' : '#5b8000'
  };

  const createElement = (elem, clss) => {
    const element = document.createElement(elem);
    element.className = clss;
    return element;
  };

  const addOverlay = (elem, text, colorBg) => {
    const hasPosition = getComputedStyle(elem).position !== 'static';
    if (!hasPosition) elem.classList.add('-js-overlay');
    const span = createElement('span', '-js-overlay-border');
    span.style.setProperty('--overlay-bg-color', colorBg);
    span.style.setProperty('--overlay-color', colorText);
    span.style.setProperty('--overlay-text', '"' + text + '"');
    elem.appendChild(span);
  }

  const outlineLandmarks = (_ => {

    const groupQuery = ':is(header,nav,main,aside,footer,section,form,[role=banner],[role=navigation],[role=main],[role=complementary],[role=contentinfo],[role=form],[role=search],[role=region])';

    const getText = (elem, text, role) => {
      if (text in colors) return text;
      return (role in colors) ? role : text;
    };

    const group = document.querySelectorAll(groupQuery);
    for (const elem of group) {
      const role = elem.getAttribute('role');
      const tag = elem.tagName.toLowerCase();
      const text = getText(elem, tag, role);
      addOverlay(elem, text, colors[text]);
    }

  })();


  const outlineHeadings = (_ => {

    const groupQuery = ':is(h1,h2,h3,h4,h5,h6,[role=heading])';

    const getText = (elem, text, role) => {
      if (text in colors) return text;
      if (role === 'heading') {
        text = `heading ${elem.getAttribute('aria-level') || '2'}`;
      }
      return text;
    };

    const group = document.querySelectorAll(groupQuery);
    for (const elem of group) {
      const role = elem.getAttribute('role');
      const tag = elem.tagName.toLowerCase();
      const text = getText(elem, tag, role);
      addOverlay(elem, text, colors[text] || '#c00');
    }

  })();
  
  const addStyles = (_ => {
    const style = document.createElement('style');
    style.id = 'a11y-overlay';
    style.textContent = `.-js-overlay{position:relative}.-js-overlay-border{position:absolute;inset:0;outline:2px solid var(--overlay-bg-color,#000);outline-offset:-2px;pointer-events:none;width:100%}.-js-overlay-border::after{all:unset;background-color:var(--overlay-bg-color,#000);content:var(--overlay-text, '???');position:absolute;top:0;right:0;color:var(--overlay-color,#fff);font-size:12px;font-weight:700;letter-spacing:.03em;text-shadow:0 0 1px #000;padding:2px 4px 1px}`;
    document.head.appendChild(style);
  })();

})();


// Minified JS (2015 bytes) for bookmarklet:
// javascript:const outliner=(e=>{'use strict';const o={header:'#eb0000',banner:'#eb0000',aside:'#8a7500',complementary:'#8a7500',footer:'#268500',contentinfo:'#268500',form:'#062',search:'#062',main:'#0076d1',nav:'#8a7500',navigation:'#8a7500',section:'#8352ff',region:'#8352ff',h1:'#008a27','heading 1':'#008a27',h2:'#007cad','heading 2':'#007cad',h3:'#8352ff','heading 3':'#8352ff',h4:'#db009d','heading 4':'#db009d',h5:'#d63d00','heading 5':'#d63d00',h6:'#5b8000','heading 6':'#5b8000'},t=(e,o,t)=>{'static'!==getComputedStyle(e).position||e.classList.add('-js-overlay');const r=((e,o)=>{const t=document.createElement(e);return t.className=o,t})('span','-js-overlay-border');r.style.setProperty('--overlay-bg-color',t),r.style.setProperty('--overlay-color','#fff'),r.style.setProperty('--overlay-text','\''+o+'\''),e.appendChild(r)};(e=>{const r=(e,t,r)=>t in o?t:r in o?r:t,a=document.querySelectorAll(':is(header,nav,main,aside,footer,section,form,[role=banner],[role=navigation],[role=main],[role=complementary],[role=contentinfo],[role=form],[role=search],[role=region])');for(const e of a){const a=e.getAttribute('role'),n=r(0,e.tagName.toLowerCase(),a);t(e,n,o[n])}})(),(e=>{const r=(e,t,r)=>t in o?t:('heading'===r&&(t=`heading ${e.getAttribute('aria-level')||'2'}`),t),a=document.querySelectorAll(':is(h1,h2,h3,h4,h5,h6,[role=heading])');for(const e of a){const a=e.getAttribute('role'),n=r(e,e.tagName.toLowerCase(),a);t(e,n,o[n]||'#c00')}})(),(e=>{const o=document.createElement('style');o.id='a11y-overlay',o.textContent='.-js-overlay{position:relative}.-js-overlay-border{position:absolute;inset:0;outline:2px solid var(--overlay-bg-color,#000);outline-offset:-2px;pointer-events:none;width:100%}.-js-overlay-border::after{all:unset;background-color:var(--overlay-bg-color,#000);content:var(--overlay-text, \'???\');position:absolute;top:0;right:0;color:var(--overlay-color,#fff);font-size:12px;font-weight:400;letter-spacing:.03em;text-shadow:0 0 1px #000;padding:2px 4px 1px}',document.head.appendChild(o)})()})();

              
            
!
999px

Console