Frontend.fyi

Tutorial

Auto-hiding Sticky Navigation With Motion for React

CSS sticky makes sticky headers super easy. But what if you want to make an auto-hiding header?

Try it yourself in our playground

Follow along with the tutorial, or just play around with the code. PRO members can fork this code and save it to their account.

Go Pro

Playgrounds are part of PRO

Frontend.fyi Playgrounds let you take any code example and turn it into a live, editable sandbox — so you can tweak the code, build on it, and learn by doing.

This feature is part of Frontend.fyi PRO, which gives you lifetime access to:

  • Interactive playgrounds (like this one)
  • Full courses (Framer Motion, CSS, and more coming)
  • Copy-paste UI recipes with video walkthroughs
  • Your own public profile to showcase projects and experiments (soon!)

If you're ready to go beyond just watching tutorials and actually build things yourself, PRO is for you.

Using CSS position: sticky makes sticky headers super easy. One thing that isn’t as easy is making a sticky header that hides when the user scrolls down and shows when the user scrolls up. This is a common pattern that is actually a little bit harder to achieve.

In this video, we’ll use Framer Motion to create an auto-hiding sticky navigation. We’ll use the useMotionValueEvent hook to listen to the scroll position and update the visibility of the navigation based on the scroll direction.

Eager to learn more?

I think this video might be a good fit for you too!