123

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.

            
              <h1>Accessible animated same-page linking with <code>focus()</code></h1>
<nav role="navigation">
  <ul>
    <li><a href="#section1">Section 1</a></li>
    <li><a href="#section2">Section 2</a></li>
    <li><a href="#section3">Section 3</a></li>
  </ul>
</nav>

<section id="section1">
  <h2>Section 1</h2>
   <p>Donec tempus tempus tellus, ac lacinia turpis mattis ac. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh, <a href='#'>iaculis pretium</a> sem orci aliquet mauris. Potenti et eros sed justo commodo bibendum non at nunc. Donec et nisi dictum felis sollicitudin congue. Suspendisse potenti H<sub>2</sub>0. </p><p>Donec a congue leo. Donec et nisi dictum <a href='#'>felis sollicitudin</a> congue. Aliquam tincidunt velit sit amet ante hendrerit tempus. Maecenas sit amet tellus nec mi gravida posuere non pretium magna. Fusce ac sodales <abbr title='Cascading Style Sheets'>CSS</abbr> magna. Nulla lobortis tempus commodo. Duis sagittis, est sit amet gravida tristique, purus lectus venenatis urna, id molestie magna risus ut nunc. Vestibulum <code>text-align : justify</code> lacus. Aliquam nisl enim&hellip; tristique tempus placerat at, posuere in lectus. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh (iaculis pretium sem orci aliquet mauris). </p><p>Donec a congue leo. Vestibulum sit amet ipsum lacus. Nunc <a href='#'>iaculis risus</a> vel orci ornare dignissim sed vitae nulla. Donec tempus tempus tellus, ac lacinia turpis mattis ac. Cras molestie risus a enim convallis vitae luctus libero lacinia. Suspendisse potenti cras molestie, risus a enim convallis vitae luctus libero lacinia. Maecenas sit amet tellus nec mi gravida posuere non pretium magna. Cras molestie risus a enim Convallis; vitae luctus libero lacinia. Fusce ac sodales magna. Curabitur consectetur faucibus nisl ac varius. </p> 
</section>

<section id="section2">
  <h2>Section 2</h2>
   <p>Maecenas sit amet tellus &ndash; nec mi gravida posuere non pretium magna. Potenti et eros sed justo commodo bibendum non at nunc. Suspendisse potenti cras molestie, risus a enim convallis vitae luctus libero lacinia. Suspendisse <del>potenti</del>. Donec a congue leo. Suspendisse potenti. Duis sagittis, est sit amet gravida tristique, purus lectus venenatis urna, id &#8216;molestie&#8217; magna risus ut nunc. Nulla vel magna sit amet dui <a href='#'>lobortis</a> commodo vitae vel nulla. Cras molestie risus a enim &#8216;convallis vitae&#8217; luctus libero lacinia. </p><p>Donec tempus tempus tellus, ac lacinia turpis mattis ac. Donec et nisi dictum felis sollicitudin congue. Duis sagittis, est sit amet gravida tristique, purus lectus venenatis urna, id molestie magna risus ut nunc. Nulla auctor eleifend turpis consequat pharetra. Donec et nisi dictum felis, sollicitudin, congue Heydon&#8482;. Maecenas sit amet tellus nec mi gravida posuere non pretium magna. </p><p>Fusce ac sodales <code>.generate()</code> magna. Nulla lobortis tempus commodo? Donec tempus tempus tellus, ac lacinia turpis mattis ac. Cras molestie risus a enim convallis vitae luctus libero lacinia. Nunc iaculis risus vel orci ornare dignissim sed vitae nulla. Donec a congue leo? Duis sagittis, est sit amet gravida tristique, purus lectus venenatis urna, id &#8216;molestie&#8217; magna risus ut nunc. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh, iaculis pretium sem orci aliquet mauris. Vestibulum <code>text-align : justify</code> lacus. </p> 
</section>

<section id="section3">
  <h2>Section 3</h2>
   <p>Donec a congue leo. Suspendisse potenti cras molestie, risus a enim convallis vitae luctus libero lacinia. Nunc iaculis risus vel orci ornare dignissim sed vitae nulla. <strong>Donec a congue leo. </strong>Curabitur consectetur faucibus nisl ac varius. Vestibulum sit amet ipsum lacus. Suspendisse potenti. Nunc <a href='#'>iaculis risus</a> vel orci ornare dignissim sed vitae nulla. Potenti et eros sed justo commodo bibendum non at nunc. </p><p>Suspendisse potenti cras molestie, risus a enim convallis vitae luctus libero lacinia. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh, iaculis pretium sem orci aliquet mauris. Suspendisse potenti H<sub>2</sub>0. Fusce ac sodales magna. Potenti et eros sed justo commodo bibendum non at nunc. </p><p>Nulla vel magna sit &mdash; amet dui lobortis commodo &mdash; vitae vel nulla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam nisl enim&hellip; tristique tempus placerat at, posuere in lectus. Nulla vel magna sit amet dui lobortis commodo vitae vel nulla sit amet ante hendrerit tempus. Nulla lobortis tempus commodo. Donec tempus tempus tellus, ac lacinia turpis mattis ac! Curabitur consectetur faucibus nisl ac varius. Sed dapibus, lectus sit amet adipiscing egestas, mauris est viverra nibh (iaculis pretium sem orci aliquet mauris). </p> 
</section>

<p>By Heydon Pickering. See <a href="http://www.sitepoint.com/learning-to-focus/">article</a>.</p>
            
          
!
            
              body {
  font-family: Arial, sans-serif;
  padding: 0 30px;
}
            
          
!
            
              /* Basics lifted from a CSS Tricks demo (https://css-tricks.com/snippets/jquery/smooth-scrolling/), with focus() and URL hash updating added where commented */

$(function() {
  /* ADDED: make sections focusable */
  $('section[id]').attr('tabindex', '-1');
  /* end ADDED */
  $('a[href*=#]:not([href=#])').click(function() {
    var $linkElem = $(this);
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
      var target = $(this.hash);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if (target.length) {
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000, function() {
          /* ADDED: focus the target */
          target.focus();
          /* end ADDED */
          /* ADDED: update the URL */
          window.location.hash = $linkElem.attr('href').substring(1);
         // window.location.hash = $(this).attr('href').substring(1, $(this).attr('href').length);
          /* end ADDED */
        });
        return false;
      }
    }
  });
});
            
          
!
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.

Console