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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<button class="openglossary" aria-label="Click to access glossary">Show Glossary</button>
<section class="glossarySection">
<h1 id="glossaryHeading"
tabindex="-1" >Glossary</h1>
<button class="close" aria-label="close the glossary">X</button>
<div class="glossary">
<ul class="glossaryLetters">
<li><button class='letter selectedLetter' aria-label="Current selected, Glossary letter A">A</button></li><li><button class='letter' aria-label="Glossary letter B">B</button></li><li><button class='letter' aria-label="Glossary letter C">C</button></li><li><button class='letter' aria-label="Glossary letter D">D</button></li><li><button class='letter' aria-label="Glossary letter E">E</button></li><li><button class='letter' aria-label="Glossary letter F"
aria-hidden="true"
disabled>F</button></li><li><button class='letter' aria-label="Glossary letter G">G</button></li><li><button class='letter' aria-label="Glossary letter H">H</button></li><li><button class='letter' aria-label="Glossary letter I">I</button></li><li><button class='letter' aria-label="Glossary letter J" aria-hidden="true" disabled>J</button></li><li><button class='letter' aria-label="Glossary letter K" aria-hidden="true" disabled>K</button></li><li><button class='letter' aria-label="Glossary letter L">L</button></li><li><button class='letter' aria-label="Glossary letter M" aria-hidden="true" disabled>M</button></li><li><button class='letter' aria-label="Glossary letter N" aria-hidden="true" disabled>N</button></li><li><button class='letter' aria-label="Glossary letter O" aria-hidden="true" disabled>O</button></li><li><button class='letter' aria-label="Glossary letter P">P</button></li><li><button class='letter' aria-label="Glossary letter Q" aria-hidden="true" disabled>Q</button></li><li><button class='letter' aria-label="Glossary letter R" aria-hidden="true" disabled>R</button></li><li><button class='letter' aria-label="Glossary letter S">S</button></li><li><button class='letter' aria-label="Glossary letter T">T</button></li><li><button class='letter' aria-label="Glossary letter U" aria-hidden="true" disabled>U</button></li><li><button class='letter' aria-label="Glossary letter V">V</button></li><li><button class='letter' aria-label="Glossary letter W">W</button></li><li><button class='letter' aria-label="Glossary letter X" aria-hidden="true" disabled>X</button></li><li><button class='letter' aria-label="Glossary letter Y" aria-hidden="true" disabled>Y</button></li><li><button class='letter' aria-label="Glossary letter Z" aria-hidden="true" disabled>Z</button></li>
</ul>
<div class="glossaryContent">
<div id="letterA_content" class="letter_content currentLetter_content">
<h2 class="sr-only" tabindex="-1" id="letterA_heading">Glossary terms for Letter A follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, B</button>
<dl
title="Glossary terms for Letter A"
> <dt>Accessibility</dt>
<dd>
<p>The measure of a web page's usability by persons with one or more disabilities.</p>
</dd>
<dt>Alternative Text</dt>
<dd>
<p>
Short text used described images---usually 125 characters or less.</p>
</dd>
<dt>Assistive technologies</dt>
<dd>
<p>
Technologies (software or hardware) that increase, maintain, or improve the functional capabilities of individuals with disabilities when interacting with computers or computer-based systems.</p>
</dd>
<dt>Audio browsers</dt>
<dd>Web browsers that provides a text-to-speech capability for the blind and visually impaired.</dd>
</dl>
</div>
<div id="letterB_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterB_heading" >Glossary terms for Letter B follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, C</button>
<dl title="Glossary terms for Letter B"
> <dt>Braille terminal</dt>
<dd>
<p>Machines that convert text on a screen to braille by raising bumps through holes on a flat surface.</p>
</dd>
</dl>
</div>
<div id="letterC_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterC_heading"
>Glossary terms for Letter C follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, D</button>
<dl title="Glossary terms for Letter C"
> <dt>Captioning</dt>
<dd>
<p>The art of adding captions to a television program or movie.</p>
</dd>
<dt>Captions</dt>
<dd>
<p>A textual representation of sounds--usually associated with television programming or movies; captions are meant to display in real time and to capture speech sounds and sounds beyond speech in some cases. </p>
</dd>
<dt>Clickability cues</dt>
<dd>
<p>
A visual indication that a given word or item on a Web page is clickable. Cues that can be used to indicate the clickability of an item include color, underlining, bullets, and arrows.
</p>
</dd>
</dl>
</div>
<div id="letterD_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterD_heading" >Glossary terms for Letter D follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, E</button>
<dl title="Glossary terms for Letter D"
> <dt>Disability</dt>
<dd>
<p>A limitation in an ability</p>
</dd>
</dl>
</div>
<div id="letterE_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterE_heading">Glossary terms for Letter E follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, G</button>
<dl title="Glossary terms for Letter E"
> <dt>Early Adopters</dt>
<dd>
<p>
A user who has a tendency to embrace new technology before the majority.
</p>
</dd>
</dl>
</div>
<div id="letterG_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterG_heading">Glossary terms for Letter G follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, H</button>
<dl title="Glossary terms for Letter G"
> <dt>Graceful Degradation</dt>
<dd>
<p>When a site utilizes new technology, if disabled, the content maintains effectiveness for the users. </p>
</dd>
</dl>
</div>
<div id="letterH_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterH_heading">Glossary terms for Letter H follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, I</button>
<dl title="Glossary terms for Letter H"
> <dt>Heat maps</dt>
<dd>
<p>Color-based representations of areas of interest/focus points; generally associated with eye-tracking software. </p>
</dd>
</dl>
</div>
<div id="letterI_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterI_heading">Glossary terms for Letter I follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, L</button>
<dl title="Glossary terms for Letter I"
> <dt>Internationalization</dt>
<dd>
<p>A system whose primary design has been developed to work in multiple languages and in the cultural contexts of different locales.</p>
</dd>
</dl>
</div>
<div id="letterL_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterL_heading">Glossary terms for Letter L follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, P</button>
<dl title="Glossary terms for Letter L"
> <dt>Late adopters</dt>
<dd>
<p>Individuals who are hestitant to adopt new technology.</p>
</dd>
<dt>Localization</dt>
<dd>
<p>Customizing or personalizing a national or international product for a local market.</p>
</dd>
<dt>Long Descriptions</dt>
<dd>
<p>Descriptions that are written for complex figures and tagged via the long desc attribute; though not currently supported by most Web browsers, the long desc attribute is a planned feature in the next iteration of Firefox.</p>
</dd>
</dl>
</div>
<div id="letterP_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterP_heading">Glossary terms for Letter P follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, S</button>
<dl title="Glossary terms for Letter P"
> <dt>Programmatic Focus </dt>
<dd>
<p>Where the computer's focus is on a Web page. </p>
</dd>
</dl>
</div>
<div id="letterS_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterS_heading">Glossary terms for Letter S follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, T</button>
<dl title="Glossary terms for Letter S"
> <dt>Screen reader</dt>
<dd>
<p>A software program used to allow reading of content and navigation of the screen using speech or Braille output. Used primarily by people who have difficulty seeing. JAWS and NVDA are examples.</p>
</dd>
<dt>Section 508 [see also 508]</dt>
<dd>
<p>Section 508 of the Rehabilitation Act was enacted to eliminate barriers in information technology, to make available new opportunities for people with disabilities, and to encourage development of technologies that will help achieve these goals. The law applies to all Federal agencies when they develop, procure, maintain, or use electronic and information technology. To learn more go to 508.gov.</p>
</dd>
</dl>
</div>
<div id="letterT_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterT_heading">Glossary terms for Letter T follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, V</button>
<dl title="Glossary terms for Letter T"
> <dt>Transcript</dt>
<dd>
<p>A text only version of what's said in a movie or television program; they are not real time and they generally are limited to speech only; they are not a recommended substitute for captions.</p>
</dd>
</dl>
</div>
<div id="letterV_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterV_heading">Glossary terms for Letter V follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to Next Letter, W</button>
<dl title="Glossary terms for Letter V"
> <dt>Visual Focus </dt>
<dd>
<p>Where the user's focus is on a Web page; generally represented by a dashed box that appears around items on the page and associated with tabbing.</p>
</dd>
</dl>
</div>
<div id="letterW_content" class="letter_content">
<h2 class="sr-only" tabindex="-1" id="letterW_heading">Glossary terms for Letter W follow </h2><button class="sr-only" onclick="goToNextLetter()" tabindex="-1">Go to First Letter, A</button>
<dl title="Glossary terms for Letter W"
> <dt>WCAG 2.0 </dt>
<dd>
<p>The Web Content Accessibility Guidelines (WCAG) 2.0 is focused on providing an international technical standard for web content. It has 12 guidelines that are organized under four principles: perceivable, operable, understandable, and robust. The guidelines each have a testable success criteria, which are at three levels: A, AA, and AAA.</p>
</dd>
</dl>
</div>
</div>
</div>
</section>
h1, h2, h3, h4, h5 {
font-family: Gentium Basic;
font-weight: normal;
font-style: normal;
}
button {
font-family: Inknut Antiqua;
font-weight: 700;
font-style: normal;
padding: 9px;
letter-spacing: .2rem;
font-variant: small-caps;
}
body {
font-family: Quattrocento Sans;
font-weight: normal;
font-style: normal;
}
.glossarySection {
display: none;
position: relative;
margin-top: 2rem;
border: 1px solid #000;
width: 75%;
padding-left: 15px;
}
.letter, .close {
background: none;
border: none;
color: inherit;
cursor: pointer;
font: inherit;
padding: 0;
outline: inherit;
}
.letter:disabled {
color: #c0c0c0;
}
.close {
position: absolute;
right: 10px;
top: 5px;
border: 1px solid #000;
padding: 5px 6px 3px 8px;
border-radius: 50%;
font-size: 1rem;
}
.sr-only {
position:absolute;
left:-10000px;
top:auto;
width:1px;
height:1px;
overflow:hidden;
}
.glossary {
display: grid;
grid-template-columns: .15fr 1fr;
}
.glossaryLetters {
margin-left: -2.4rem;
margin-top: 1.25rem;
list-style-type: none;
}
.glossaryLetters li {
line-height: 2rem;
font-weight: 800;
}
.hide {
visibility: hidden;
}
.show {
display: block;
}
.selectedLetter {
text-decoration: solid underline navy .25rem;
}
.letter_content {
display: none;
}
.currentLetter_content {
display: block;
}
/*Newly added classes follow*/
.letter:focus ,.close:focus {
background-color: navy;
color: white;
}
#glossaryHeading:focus, .close:focus {
outline: blue;
}
.letter:focus {
outline: none;
text-decoration: none;
border: 2px solid #000;
border-radius: 300px;
padding-left: 10px;
padding-right: 5px;
padding-top: 2px;
}
.letter:focus-visible {
outline: none;
}
const state = {
neverOpened: true,
currentLetter: 'A'
}
const alphabet = ['A','B','C','D','E','G','H','I','L','P','S','T','V','W'];
const openglossary = document.querySelector('.openglossary');
const glossaryHeading = document.querySelector('#glossaryHeading');
const glossarySectionElement = document.querySelector('.glossarySection');
const switchSelectedLetters = (target) => {
const selector = "selectedLetter";
const currentSelectedLetter = document.querySelector(`.${selector}`);
const currentAria = currentSelectedLetter.getAttribute("aria-label");
const targetAria = target.getAttribute("aria-label");
const selectionText = "Current selected, ";
//use [...selectionText] because we want number of characters, not code units.
currentSelectedLetter.setAttribute("aria-label", currentAria.substring([...selectionText].length))
currentSelectedLetter.classList.remove(selector);
target.setAttribute("aria-label", selectionText + targetAria);
target.classList.add(selector);
}
const switchShowingLetterContent = (letter) => {
const currentlyShowingLetter = document.querySelector('.currentLetter_content');
const currentHeader = currentlyShowingLetter.firstElementChild;
currentHeader.setAttribute("aria-hidden", "true"); currentlyShowingLetter.classList.remove('currentLetter_content');
state.currentLetter = letter;
const letterToShow = document.getElementById(`letter${letter}_content`);
letterToShow.classList.add('currentLetter_content');
}
const goToNextLetter = () => {
const {currentLetter} = state;
const placeInAlphabet = alphabet.indexOf(currentLetter);
const nextLetterIndex = (placeInAlphabet === (alphabet.length - 1)) ? 0 : placeInAlphabet + 1;
const nextLetter = alphabet[nextLetterIndex];
const nextLetterButtonSelector = `.letter[aria-label="Glossary letter ${nextLetter}"]`;
const nextLetterButton = document.querySelector(nextLetterButtonSelector);
setTimeout(() => {
nextLetterButton.focus();
}, 16);
}
const focusLetterContent = (letter) => {
console.log("focusLetterContent")
const letterToFocus = document.getElementById(`letter${letter}_heading`);
console.log(letterToFocus);
letterToFocus.setAttribute("aria-hidden", "false");
setTimeout(() => {
letterToFocus.focus();
}, 16);
}
const showGlossaryTerm = (e) => {
const target = e.target;
const letter = target.textContent;
switchSelectedLetters(target);
switchShowingLetterContent(letter);
focusLetterContent(letter);
}
const openGlossarySection = () => {
if (state.neverOpened) {
const closeglossary = document.querySelector('.close');
closeglossary.onclick = closeGlossarySection;
//attach onclick handlers to all glossary buttons
const glossaryLetter = document.querySelectorAll('.letter');
glossaryLetter.forEach((letter) => {
letter.onclick = showGlossaryTerm;
});
}
glossarySectionElement.classList.add('show');
openglossary.classList.add("hide");
setTimeout(() => {
glossaryHeading.focus();
}, 16);
};
const closeGlossarySection = () => {
glossarySectionElement.classList.remove('show');
openglossary.classList.remove("hide");
setTimeout(() => {
openglossary.focus();
}, 16);
};
openglossary.onclick = openGlossarySection;
Also see: Tab Triggers