In a menu, visitors want to see which page they’re on. TanStack Start’s Link knows when its page is open, and gives you three ways to style the active link: activeProps, inactiveProps and the data-status attribute.
This post styles the header of a real app, the Bookshop, with each one, then shows how exact stops a link from staying active on the pages under it.
Syntax
<Link
to="<address>"
activeProps={{ className: "<classes while the page is open>" }}
inactiveProps={{ className: "<classes while it isn’t>" }}
activeOptions={{ exact: <true or false> }}
>
<text>
</Link>
activeProps: settings the link gets while its page is open. AclassNamehere is added to the link’s own classes.inactiveProps: settings the link gets while its page isn’t open.activeOptions={{ exact: true }}: makes the link active only on its own address, not on the addresses under it. It’s off by default.toand<text>: the address and the text, as for anyLink.
Each option is described in the navigation guide (opens in a new tab) and the ActiveLinkOptions reference (opens in a new tab).
Step 1: Make the Open Page’s Link Bold
Give each link in the header an activeProps with the Tailwind CSS class font-bold:
<nav className="mx-auto flex max-w-2xl gap-6 px-8 py-4 text-lg">
<Link to="/" activeProps={{ className: "font-bold" }}>
Home
</Link>
<Link to="/books" activeProps={{ className: "font-bold" }}>
Books
</Link>
<Link to="/about" activeProps={{ className: "font-bold" }}>
About
</Link>
</nav>
On the Books page, its link is bold:

Step 2: Dim the Other Links
Add inactiveProps to style the links of the pages that aren’t open. Here they turn gray:
<nav className="mx-auto flex max-w-2xl gap-6 px-8 py-4 text-lg">
<Link
to="/"
activeProps={{ className: "font-bold" }}
inactiveProps={{ className: "text-gray-500" }}
>
Home
</Link>
<Link
to="/books"
activeProps={{ className: "font-bold" }}
inactiveProps={{ className: "text-gray-500" }}
>
Books
</Link>
<Link
to="/about"
activeProps={{ className: "font-bold" }}
inactiveProps={{ className: "text-gray-500" }}
>
About
</Link>
</nav>

Step 3: Or Style the data-status Attribute
Link also marks the link of the open page with data-status="active". Tailwind CSS can style that attribute with the data-[status=active]: variant, so you don’t need activeProps at all:
<nav className="mx-auto flex max-w-2xl gap-6 px-8 py-4 text-lg">
<Link to="/" className="data-[status=active]:font-bold">
Home
</Link>
<Link to="/books" className="data-[status=active]:font-bold">
Books
</Link>
<Link to="/about" className="data-[status=active]:font-bold">
About
</Link>
</nav>
The header looks exactly as in Step 1. Use whichever style reads better to you.
Step 4: Keep a Parent Link from Matching the Pages Under It
A link is active on its own address and on every address under it. With a page at /books/new, the Books link stays bold there too:

Add activeOptions={{ exact: true }} to the Books link to make it active only on /books itself:
<Link
to="/books"
activeProps={{ className: "font-bold" }}
activeOptions={{ exact: true }}
>
Books
</Link>

Most menus want the default, so a section stays highlighted on all of its pages. Add exact only where you don’t.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Putting the active class in className | Every link gets it, open or not | Put it in activeProps, or use data-[status=active]: |
| Expecting a link to be active only on its own address | Books stays bold on /books/new | Add activeOptions={{ exact: true }} |
FAQ
What does Link add to the open page’s link? data-status="active", aria-current="page" and, when you don’t set activeProps, the class active (see link.tsx (opens in a new tab) in TanStack Router’s repository). aria-current="page" tells screen readers which link is the current page (WAI-ARIA (opens in a new tab)).
Is a link to the home page active on every page? No. A link to / is active only on the home page, so it doesn’t need exact.
Conclusion
activeProps styles the open page’s link, inactiveProps styles the rest, data-[status=active]: does the same from CSS, and exact keeps a parent link from matching the pages under it.
Additional Resources
- Navigation (opens in a new tab) in the TanStack Router docs, with active and inactive props
- ActiveLinkOptions (opens in a new tab) reference
- Hover, focus and other states (opens in a new tab) in the Tailwind CSS docs, with data attributes
Related
- TanStack Start Tutorial — Part 3: Pages and Links: File-Based Routing
- TanStack Start Tutorial for Beginners, every part of the series
TanStack, React and other names mentioned are trademarks of their respective owners. JD Bots isn’t affiliated with or endorsed by TanStack.
0 comments