Dev Helpers
← Back

Give scroll targets an extra margin

Give scroll targets an extra margin with native CSS. The preview includes a small shared demo stylesheet.

Open this example in the interactive library

Source code

<style>
  .demo {
    overflow: auto;
    height: 6rem;
  }
  #end {
    scroll-margin-top: 1rem;
  }
</style>
<div class="demo">
  <a href="#end">Jump to heading</a>
  <p style="height: 8rem">Scrollable content</p>
  <p id="end" style="min-height: 5rem">Target with top margin</p>
</div>