<nav class="nav"> 
  <a class="scroll-link" href="#link1">Link 1</a> 
  <a class="scroll-link" href="#link2">Link 2</a> 
  <a class="scroll-link" href="#link3">Link 3</a> 
  <a class="scroll-link" href="#link4">Link 4</a>
</nav>
<p>start</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<h2 class="destination" id="link1">Destination 1</h2>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<h2 class="destination" id="link2"> Destination 2</h2>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>

<h2 class="destination" id="link3">Destination 3</h2>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>

<h2 class="destination" id="link4">Destination 4</h2>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
<p>scroll</p>
html,
body {
  scroll-behavior: smooth;
}
.nav {
  display: flex;
  position: fixed;
  position: -webkit-sticky;
  position: sticky;
  z-index: 99;
  left: 0;
  right: 0;
  top: 0;
  min-height: 100px;
  background: rgba(100, 100, 200, 0.9);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.nav a {
  color: #000;
  font-weight: bold;
  text-decoration: none;
  font-weight: bold;
  margin: auto;
  padding: 10px 20px;
  background: #f9f9f9;
}
.nav a.current,
.nav a:hover {
  background: blue;
  color: #fff;
}
h2 {
  background: red;
  color: #fff;
}
.destination {
  scroll-margin: 100px 0 0 0;
}

Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.