<nav aria-labelledby="toc-heading">
  <h2 id="toc-heading">Table of contents</h2>
  <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>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam euismod, tortor nec pharetra ultricies, ante erat imperdiet velit, nec laoreet enim lacus a velit. Nam luctus, enim in interdum condimentum, nisl diam iaculis lorem, vel volutpat mi leo sit amet lectus. Praesent non odio bibendum magna bibendum accumsan.</p>
</section>
<section id="section2">
  <h2>Section 2</h2>
  <p>Nullam at diam nec arcu suscipit auctor non a erat. Sed et magna semper, eleifend magna non, facilisis nisl. Proin et est et lorem dictum finibus ut nec turpis. Aenean nisi tortor, euismod a mauris a, mattis scelerisque tortor. Sed dolor risus, varius a nibh id, condimentum lacinia est. In lacinia cursus odio a aliquam. Curabitur tortor magna, laoreet ut rhoncus at, sodales consequat tellus.</p>
</section>
<section id="section3">
  <h2>Section 3</h2>
  <p>Phasellus ac tristique orci. Nulla maximus justo nec dignissim consequat. Sed vehicula diam sit amet mi efficitur vehicula in in nisl. Aliquam erat volutpat. Suspendisse lorem turpis, accumsan consequat consectetur gravida, pellentesque ac ante. Aliquam in commodo ligula, sit amet mollis neque. Vestibulum at facilisis massa.</p>
</section>
@import url('https://fonts.googleapis.com/css?family=Asap:400,400i,700');

html {
  font-size: 125%;
  font-family: Asap, sans-serif;
}

body {
  max-width: 40rem;
  padding: 0 1rem;
  margin: 1.5rem auto;
}

* {
  color: inherit;
}

[aria-labelledby="toc-heading"] {
  padding: 1rem;
  border: 2px solid;
}

[aria-labelledby="toc-heading"] * {
  margin: 0;
}

section:not(:target) {
  display: none;
}
// Choose the default section on page load
// And scroll to the top to show nav
window.onload = function () {
  window.location.hash = 'section1'
  document.documentElement.scrollTop = 0
}
Rerun