Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <div class="container">
  <h1>Drawing attention to internal focus</h1>
  <p>When using internal document links, it's important to manage keyboard focus for screen-reader users <i>and</i> draw sighted users' attention to the content you want them to focus on. In this demo, activating the internal links moves browser focus to their target headings; then, scripting applies a <code>highlight</code> class to the heading's parent and removes the class after the highlight animation ends.</p>
  <p><b>Note:</b> the <code>:focus-within</code> selector is not ideal here; it will match every time your user focuses on an element in a given region. We want to show our highlight <i>only</i> when the user clicks an intra-document link.</p>
  <h2>Demo</h2>
  <div class="demo js-demo">
    <header>
      <nav>
        <a href="#charismatic-introductions">Charismatic introductions</a><a href="#specialty-fans">Specialty fans</a>
      </nav>
    </header>
    <section>
      <h3 id="charismatic-introductions" tabindex="-1">Charismatic introductions</h3>
      <p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. <a href="#">Ipsam, culpa commodi</a>. Totam amet maxime quo pariatur.
        Ipsa ullam rem nam nesciunt! Dolores assumenda dolorum eveniet ullam dicta, facilis dignissimos reprehenderit!
        Lorem, ipsum dolor sit amet consectetur adipisicing elit. Numquam quasi perspiciatis ea impedit, unde, qui
        veritatis
        provident adipisci nesciunt aperiam laborum consequuntur. Atque nemo quisquam laborum numquam? Vitae, dolorem
        reprehenderit.</p>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Nulla ea cupiditate, odit numquam, possimus aliquam
        modi
        quibusdam accusamus, enim doloremque laborum qui? Facilis veritatis numquam quaerat perspiciatis sint iste
        tenetur!
        Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quam facere quo culpa repudiandae porro, consequuntur
        sequi ad mollitia maiores quas exercitationem, delectus atque pariatur fugiat voluptates distinctio cupiditate
        ex
        animi! Lorem ipsum dolor sit amet consectetur adipisicing elit. Error facilis eaque officiis, voluptatem harum
        excepturi. Debitis veniam est itaque, perferendis omnis quidem nesciunt excepturi ducimus, quibusdam deserunt
        laudantium in qui. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Illo, excepturi? Facilis,
        voluptatibus
        id eligendi illum cupiditate harum dolorum voluptatem at inventore optio, amet porro placeat. Quod et excepturi
        mollitia aspernatur.</p>
      <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Pariatur eos dicta, suscipit facilis eligendi illo
        magni
        incidunt provident porro similique sint, harum sunt consequuntur? Minus cupiditate reiciendis enim cum
        exercitationem.</p>
    </section>
    <section>
      <h3 id="specialty-fans" tabindex="-1">Specialty fans</h3>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Odio, non pariatur sint eius ipsa omnis dicta quos
        deserunt magni facilis facere consequatur architecto asperiores quibusdam tempore iste excepturi impedit rerum!
        Lorem, ipsum dolor sit amet consectetur adipisicing elit. Vel, <a href="#">dolor unde</a>. Laudantium laboriosam aliquam non
        quis
        mollitia nesciunt quibusdam eligendi distinctio nobis, architecto unde quasi provident temporibus voluptas
        voluptatum voluptate. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Id consequatur totam officiis
        repudiandae! Facilis deleniti quas vel molestias doloremque nisi aliquid inventore modi ullam. Enim id odio
        ipsum
        harum est.</p>
      <p>Lorem, ipsum dolor sit amet consectetur adipisicing elit. Amet, officiis deserunt. Vitae tempora accusamus ex
        neque
        nobis, ut sequi provident obcaecati quas, expedita quidem eveniet saepe labore nesciunt eligendi maiores.</p>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Ipsa iusto est nemo quas deserunt, dolore itaque
        earum!
        Assumenda incidunt voluptas quidem quo ratione, odio illo ducimus? Praesentium harum quibusdam quod. Lorem ipsum
        dolor sit amet consectetur adipisicing elit. Quaerat possimus quasi doloremque voluptatem, expedita esse ducimus
        cupiditate vitae adipisci voluptas excepturi ipsam culpa ullam ad animi accusamus quisquam. Dolore, molestias?
      </p>
    </section>
  </div>
</div>
              
            
!

CSS

              
                *,
*:after,
*:before {
  box-sizing: border-box;
}

/* FOCUS-MANAGEMENT STYLES */

:focus {
  outline: 3px dashed #0e4bff;
}

/*Don't show focus outline for negative-index elements */
[tabindex="-1"]:focus {
  outline: 0;
}

.highlight {
  animation: highlight 1.25s ease-in-out;
}

@keyframes highlight {
  0% {
    background: #f9f98b;
  }
  100% {
    background: none;
  }
}

/* OTHER STYLES */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font: 10px / 1.15 sans-serif;
  font: calc(100% * 0.625) / 1.15 sans-serif;
}

body {
  font: 1.6rem/1.25 "HelveticaNeue-Light", "Helvetica Neue Light",
    "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
  color: #252525;
  margin-bottom: 1.5em;
}

@media screen and (min-width: 680px) {
  body {
    font-size: 1.92em;
    line-height: 1.4;
  }
}

h1 {
  font-size: 2em;
}

h1,
h2:not(:first-child) {
  margin-bottom: 0;
}
h1 + * {
  margin-top: 1.25em;
}

h2:first-child {
  margin-top: 1.5em;
}
h2 + p,
p:first-child {
  margin-top: 1em;
}

p {
  max-width: 75ch;
}

code {
  background-color: #eee;
  padding: 0.1em 0.2em;
  color: #000;
}

.container {
  width: 95%;
  max-width: 100rem;
  margin: 0 auto;
}

.demo {
  max-width: 100rem;
  height: 30rem;
  overflow-y: scroll;
  padding: 1.5rem 1rem;
  margin: 0 auto;
  font-size: 0.9em;
  border: 3px solid black;
}

.demo nav {
  background: #000;
}

.demo nav a {
  display: inline-block;
  color: #fff;
  padding: 5px;
  padding: 1.2em 0.8em;
}

.demo nav a:hover,
.demo nav a:focus{
  color: #000;
  background-color: #fff;
}

.demo nav a:focus {
  outline-offset: -3px;
}

header,
section {
  padding: 0 0.75rem;
}

section > h2 {
  margin-top: 0;
}

              
            
!

JS

              
                if (!Element.prototype.matches) {
  Element.prototype.matches =
    Element.prototype.msMatchesSelector ||
    Element.prototype.webkitMatchesSelector;
}

function handleHashLinkClick(evt) {
  if (!evt.target.matches('a[href^="#"]')) {
    return;
  }
  const hash = evt.target.hash;
  const targetHeading = document.querySelector(hash);
  const parent = targetHeading.parentElement;
  targetHeading?.focus();
  return parent.classList.add("highlight");
}

function handleFocusAnimationEnd(evt) {
  if (evt.animationName === "highlight") {
    return evt.srcElement.classList.remove("highlight");
  }
  return;
}

function handleHashTargetMousedown(evt) {
  if (evt.target.matches('[tabindex="-1"]')) {
    evt.stopImmediatePropagation();
    return evt.preventDefault();
  }
  return;
}

document.addEventListener("DOMContentLoaded", function (e) {
  const demoContainer = document.querySelector(".js-demo");
  demoContainer.addEventListener("click", handleHashLinkClick, true);
  demoContainer.addEventListener("mousedown", handleHashTargetMousedown, true);
  demoContainer.addEventListener("animationend", handleFocusAnimationEnd, true);
});

              
            
!
999px

Console