HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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=>{'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)})()})();
</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, …]"</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>
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;
}
*/
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)})()})();
Also see: Tab Triggers