shadcn.io is not affiliated with official shadcn/ui
Hover Highlight Navbar Block for React
A navbar for a tile shop whose five centred links share one soft block that glides to the link you hover or focus and fades out when you leave, with the current page marked by a heavier label and a dot instead.
Installation
Overview
A navbar for React with Base UI whose links share a single highlight. The wordmark sits at the start, five links (Tiles, Surfaces, Samples, Trade and Showrooms) are centred in the bar, and a Get a quote Shine Button sits at the end. One soft block sits behind the links: hover or focus a link and it glides there, resizing to that link's width, and when you leave the list it fades out where it is. It's positioned from the link's measured box (its inline start and width), so it works in right-to-left pages, and the first time it appears it fades in over the link rather than travelling from nowhere. The current page isn't marked by the block: it has a heavier label and a dot before it, and aria-current="page". Below the md breakpoint the links fold into a menu button that opens a drawer from the bottom with the same links. The bar is 56 pixels high and takes its rails and top rule from the Guides spine; it draws no bottom border. It's built from Drawer, Guides, Shine Button and Button, with your theme's tokens for every colour. For shops, studios and catalogues with a handful of top-level sections.
FAQ
How do I change the links and the current page?
Edit PAGES at the top of the file: each entry is a label, an href and, for the page you're on, current: true. The bar and the drawer both read it. Compute current from your router and the dot, the heavier label and aria-current="page" follow. Five links fit the centred column comfortably; with more, move some into a menu.
How does the highlight find the link?
Each link reports itself on pointer enter and on focus: the block measures the link's box against the nav's (so its inline start comes out right in either text direction) and sets its offset and width. It transitions inset-inline-start, width and opacity; the first time it shows, the position changes with no transition so it appears on the link instead of travelling from the start, and when you leave it only fades. Moving between links glides.
How does it work with a keyboard and a screen reader?
The links sit in a nav landmark named Main, after the wordmark (a link home). Tab walks the wordmark, the five links and Get a quote; the highlight follows keyboard focus as it follows the pointer, and fades when focus leaves the list. The highlight is decorative and hidden from assistive technology; the current page is announced as the current page.
How does it work on a phone?
Below the md breakpoint the highlight isn't needed (there's no hover), so the links fold into a menu button beside Get a quote. It opens a drawer from the bottom: a handle, a Menu title and the same links, the current page tinted with a dot. Drag the drawer down, press Escape, tap the overlay or choose a link to close it; focus goes back to the menu button. Nothing wraps at 320 pixels.
The drawer is Base UI's, with its swipe handle; each link is the drawer's close part, rendered as a link with nativeButton={false}.
Get a quote renders the link it's given with render, with nativeButton={false}.
What happens with reduced motion?
With reduced motion the highlight appears, moves and disappears at once, with no transition at all, and the drawer opens without sliding. The band of light on Get a quote fades in where it stands instead of sweeping.
How does it sit on the page, and can it stick to the top?
The navbar is the page's first block: its + marks and rails line up with every block under it, and it draws no bottom border, because the next block's top rule is its bottom edge. To keep the bar in view while the page scrolls, add sticky top-0 z-40 bg-background/80 backdrop-blur to the header.
Related
- Pro
Animated Underline Navbar
Link highlightsA one-bar navbar for a design studio whose links draw a hairline underline in from the inline start on hover and focus and retract it toward the end, with the current page keeping its full line, using nothing but a CSS transform.
- Pro
Pill Links Navbar
Link highlightsA navbar for a sprint-planning app where the current page is a pill that slides to whichever link you choose, with the links and a Shine Button grouped at the end and hover only tinting.
- Pro
Segmented Control Navbar
Link highlightsA navbar for a meal-planning app that centres its three destinations in a tray of equal segments, each an icon, a label and a count, with one raised thumb that slides under the current one and folds to icons on a phone.
- Pro
Minimal Navbar
Link highlightsThe least navbar there is: a slim 48 px bar with a wordmark, three plain links and one Shine Button for a journaling app, with no motion, the current page marked by weight and a dot, and a bottom drawer on phones.
- Pro
Centered Logo Navbar
Cells and splitsA symmetrical navbar with a centred wordmark in its own hairline cell between two link groups and a Bag link, and a sheet menu on phones.
- Pro
SaaS Marketing Navbar
Mega menusA one-bar marketing navbar for a product roadmap tool: a wordmark, a Product menu of four areas with icons and one-line descriptions, plain links with the current page marked, Sign in and a Shine Button, and a sheet with the same links on phones.