Skip to main content

afrigov is an open-source project. It is not a government website and is not affiliated with any government.

Previewing neutral core Change

afrigov Web toolkit for government

Back to top

A plain link at the end of a long page. It takes people back to the top, where the menu and search are.

When to use

On long pages: a policy, a guide with a contents list, a long news list. As a rough rule, a page that runs to three screens or more on a phone.

When not to use

On short pages, where the top is a swipe away, and on question pages in a form. Not on every page by habit: a link nobody needs is one more thing to read past.

…the last paragraph of a long page.

Show HTML
<p class="ag-mt-0">…the last paragraph of a long page.</p>
<div class="ag-back-to-top">
  <a class="ag-back-to-top__link" href="#top">Back to top</a>
</div>

How it works

  • Put id="top" on body, and point the link at #top.
  • Put it after the last of the page's content, inside main, not in the footer.
  • The text is "Back to top". The arrow is drawn in CSS and is not read out.
  • No script. Where the browser allows, the page scrolls up smoothly; it jumps for anyone who asks for less motion.
<body id="top">
  …
  <main class="ag-main" id="main" tabindex="-1">
    …
    <div class="ag-back-to-top">
      <a class="ag-back-to-top__link" href="#top">Back to top</a>
    </div>
  </main>

Sticky

ag-back-to-top--sticky keeps the link on the bottom edge of the screen while you read, then settles at the end of the content. Use it on very long pages, with a contents list. Put it as the last thing inside the content's column, so it stays within that column and never floats over the footer.

It is a strip on the page background with a hairline, not a round button over the text. While it is there, the page keeps a matching gap at the bottom, so whatever a keyboard user tabs to is never hidden under it. This page uses it.

<div class="ag-back-to-top ag-back-to-top--sticky">
  <a class="ag-back-to-top__link" href="#top">Back to top</a>
</div>

Accessibility

  • The target is body, so after the jump the next Tab goes to the skip link, then the header. Keyboard users start again from the top, as they expect.
  • It is a link, not a button, because it goes somewhere: a place on the page.
  • No floating icon-only button. It would need a hidden label, cover text, and appear and vanish as you scroll.
  • The link is at least 44px tall, so it is easy to tap.