css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <a class=skip_lnk href="#main_h1">Skip to main content</a>

<nav class=fakeNav>
  <ul class=fakeNav_lst>
    <li class=fakeNav_li><a class=fakeNav_lnk href>dummy nav link</a></li>
    <li class=fakeNav_li><a class=fakeNav_lnk href>dummy nav link</a></li>
  </ul>
</nav>

<main class=main>

  <!-- tabindex = -1 is required for iOS with JS unavailable -->
  <h1 class=main_h1 id=main_h1 tabindex=-1>Accessible "Skip to content" link for desktop and mobile</h1>
  
  <p class=main_p>Assistive technologies struggle with "skip links" on mobile and touch devices.</p>
  
  <p class=main_p>This solution corrects experienced issues across desktop, iOS and Android.</p>
  
  <p class=main_p>Activating the skip link anchor (only available via tab key) moves the focus to its <code class=main_code>href</code> which is problematic on iOS and Android devices.</p>
  
  
  <figure>
    <figcaption>HTML</figcaption>
    <pre><code class=language-markup spellcheck=false contenteditable>&lt;a class=skip_lnk href="#main_title"&gt;Skip to main content&lt;/a&gt;

&lt;!-- Nav, etc --&gt;

&lt;h1 class="main_title" id="main_title" tabindex="-1"&gt;Page heading&lt;/h1&gt;
</code></pre>
  </figure>
  
  <p class=main_p><code class=main_code>tabindex="-1"</code> resolves iOS issues.</p>

  <figure>
    <figcaption>CSS</figcaption>
    <pre><code class=language-css spellcheck=false contenteditable>.skip_lnk {
  display: block;
  position: absolute;
  left: 0.25em;
  top: -4em;
  padding: 0.5em 1em;
  text-decoration: none;
  font-weight: bold;
}
.skip_lnk:focus {
  top: 0.25em;
  color: #fff;
  background-color: #3B2D4A;
  outline: #fff solid 0.25rem;
  z-index: 10;
}

/* Just so you can see where the focus lands */
[tabindex="-1"]:focus {
  color: red;
  outline: #fff solid 0.125rem;
}
</code></pre>
  </figure>
  
  <p class=main_p>JavaScript is required to resolve Android issues.</p>

  <figure>
    <figcaption>JavaScript (ES6)</figcaption>
    <pre><code class=language-javascript spellcheck=false contenteditable>(() => {
  const skip_lnk = document.querySelector('.skip_lnk');
  if (skip_lnk) {
    skip_lnk.addEventListener('click', (e) => {
      e.preventDefault();
      const to_obj = document.getElementById(skip_lnk.href.substring(skip_lnk.href.indexOf('#') + 1));
      if (to_obj) {
        to_obj.focus();
      }
    });
  }
})();
</code></pre>
  </figure>

  <figure>
    <figcaption>JavaScript (ES5) - Google closure compiled 201 bytes</figcaption>
    <pre><code class=language-javascript spellcheck=false contenteditable>(function(){var a=document.querySelector(".skip_lnk");a&&a.addEventListener("click",function(b){b.preventDefault();(b=document.getElementById(a.href.substring(a.href.indexOf("#")+1)))&&b.focus()})})();
</code></pre>
  </figure>

  <p class=main_p>For a full description of the issue faced on mobile devices, and who it affects, please see the original article by Hampus Sethfors: <a class=main_lnk rel=noreferrer target=_blank href="https://axesslab.com/skip-links/">Your skip links are broken</a>.<br>The code here replaces the article's jQuery version with vanilla JavaScript.</p>

</main>



<!-- Footer codepen include -->
[[[https://codepen.io/2kool2/pen/mKeeGM]]]
            
          
!
            
              html {box-sizing: border-box;}
*,
*::before,
*::after {box-sizing: inherit;}
body {
  margin: 0;
  color: #666;
  font-family: sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: hsl(269,19%,30%);
  background-color: hsla(32,100%,85%,.35);
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg width='100%25' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cfilter id='a'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.4'/%3E%3C/filter%3E%3C/defs%3E%3C!-- %3Cpath filter='url(%23a)' opacity='.3' d='M0 0h1200v256H0z'/%3E--%3E%3Crect filter='url(%23a)' opacity='.3' width='100%25' height='100%25'/%3E%3C/svg%3E");
}
::-moz-selection {
  color: #fff;
  background-color: #000;
}
::selection {
  color: #fff;
  background-color: #000;
}


/* Skip link */

.skip_lnk {
  display: block;
  position: absolute;
  left: .25em;
  top: -4em;
  padding: .618em 1em;
  color: #fff;
  background-color: #3B2D4A;
  text-decoration: none;
  font-weight: bold;
}
.skip_lnk:focus,
x.skip_lnk {
  top: .25em;
  outline: #fff solid .25rem;
  z-index: 10;
}


/* Fake nav */
.fakeNav {
  color: #fff;
  background-color: #463b4c;
  border:2px solid #463b4c;
}
.fakeNav_lst {
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: space-around;
  list-style: none;
}
.fakeNav_li {}
.fakeNav_lnk {
  display: block;
  font-weight: bold;
  color: #fff;
  padding: .5em;
}
.fakeNav_lnk:focus {
  outline: #fff solid .125rem;
}


/* Main */
.main {padding: 0 1rem;}
.main_h1 {
  font-weight: 100;
  line-height: 1.3;
  text-align: center;
  margin-top: 2rem;
}

/* So you can see where the focus lands */
[tabindex="-1"]:focus {
  color: red;
  outline: #fff solid .125rem;
}
.main_h1 + .main_p {
  font-size: larger;
}
.main_p {
  text-align: center;
  max-width: 34em;
  margin: 1rem auto;
}
.main_lnk,
.main_lnk:visited {
  white-space: nowrap;
  color: #236ECE;
}
.main_lnk:hover,
.main_lnk:focus {
  color: #014cac;
}
.main_code {font-size:1rem}




/* Prism - is used for code highlighting from an external pen: https://codepen.io/2kool2/pen/MEbeEg */

figure {
  box-shadow: 0 2px 4px rgba(0,0,0,.125);
  background-color: rgba(255,255,255,.5);
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg height='48' style='opacity:.5' viewBox='0 0 1224 64' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'%3E%3Cfilter id='code_noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.2,.1'/%3E%3C/filter%3E%3Cpath id='code-path' fill-rule='evenodd' d='M1224 64H0V0h1224v64zM19 31a15 15 0 1 1 0 30 15 15 0 0 1 0-30z' fill='%23fcfdfc'/%3E%3CclipPath id='code-clip'%3E%3Cuse clip-rule='evenodd' xlink:href='%23code-path'/%3E%3C/clipPath%3E%3Cpath d='M0 1h1224M0 5h1224M0 9h1224M0 13h1224M0 17h1224M0 21h1224M0 25h1224M0 29h1224' stroke='%23edf3ed' stroke-width='2'/%3E%3Cpath d='M19 31a15 15 0 1 1 0 30 15 15 0 0 1 0-30zm11 8a13 13 0 0 0-22 0c-2 3-3 5-3 8 0 8 6 14 14 14s14-6 14-14c0-3-1-5-3-8z' fill='rgba(0,0,0,.2)'/%3E%3Cpath d='M40 2v60' stroke='%23b8d9b8' stroke-width='2' stroke-dasharray='2,6,2,6'/%3E%3Cuse clip-path='url(%23code-clip)' filter='url(%23code_noise)' opacity='.05' xlink:href='%23code-path'/%3E%3C/svg%3E");
  padding-left: 2rem;
  max-width:40em;
  margin: 1.5rem auto;
}
figcaption {
  font-weight: 700;
  padding: 1.5rem 0 0 .5rem;
}
pre,
pre > code {
  background-color: transparent !important;
}
pre:focus {
  outline: #fff solid .125rem;
}
pre > code {
  display:block;
  margin: 0 0 0.75rem;
  padding-left: 0.5rem;
}
            
          
!
            
              // JS required to resolve Android issues
/*
(() => {
  const skip_lnk = document.querySelector('.skip_lnk');
  if (skip_lnk) {
    skip_lnk.addEventListener('click', (e) => {
      e.preventDefault();
      const to_obj = document.getElementById(skip_lnk.href.substring(skip_lnk.href.indexOf('#') + 1));
      if (to_obj) {
        to_obj.focus();
      }
    });
  }
})();
*/

// ES5 version
/*
var skip_to_content_link = (function () {
  var skip_lnk = document.querySelector('.skip_lnk');
  if (skip_lnk) {
    skip_lnk.addEventListener('click', function(e) {
      e.preventDefault();
      var to_obj = document.getElementById(skip_lnk.href.substring(skip_lnk.href.indexOf('#') + 1));
      if (to_obj) {
        to_obj.focus();
      }
    });
  }
})();
*/


// ES5 version - Google closure compiled 201 bytes
(function(){var a=document.querySelector(".skip_lnk");a&&a.addEventListener("click",function(b){b.preventDefault();(b=document.getElementById(a.href.substring(a.href.indexOf("#")+1)))&&b.focus()})})();
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console