sigilUI

Magnetic Nav

Navigation with a sliding magnetic highlight indicator — pure CSS anchor positioning, no JS.

@sigil-ui/componentsReact

Preview

Live preview Interactive

Import

import { MagneticNav, MagneticNavItem, MagneticNavLink } from "@sigil-ui/components";

Usage

<MagneticNav>
  <MagneticNavItem>
    <MagneticNavLink href="/" active>Home</MagneticNavLink>
  </MagneticNavItem>
  <MagneticNavItem>
    <MagneticNavLink href="/docs">Docs</MagneticNavLink>
  </MagneticNavItem>
  <MagneticNavItem>
    <MagneticNavLink href="/blog">Blog</MagneticNavLink>
  </MagneticNavItem>
</MagneticNav>

How it works

A ::before pseudo-element on the <ul> uses CSS anchor positioning to track whichever <li> contains a hovered, focused, or active link:

li:has(a:is(:hover, :focus-visible, [data-active])) {
  anchor-name: --sigil-magnetic-target;
}

ul::before {
  position-anchor: --sigil-magnetic-target;
  left: anchor(left);
  top: anchor(top);
  width: anchor-size(width);
  height: anchor-size(height);
}

The indicator transitions smoothly between positions using --s-duration-fast and --s-ease-out tokens. No JavaScript required.

Vertical

Live preview Interactive

Sub-components

  • <MagneticNav> — outer <nav> wrapper
  • <MagneticNavItem> — <li> wrapper for each link
  • <MagneticNavLink> — <a> with active prop for current page

Props

MagneticNav

PropTypeDefaultDescription
orientation"horizontal" | "vertical""horizontal"Layout direction of the nav list.
PropTypeDefaultDescription
activebooleanfalseMark this link as the currently active page. Sets aria-current="page".

Token integration

CSS VariablePurpose
--s-navbar-item-gapGap between nav items
--s-radius-lgList container radius
--s-radius-mdLink and indicator radius
--s-button-padding-xLink horizontal padding
--s-spacing-xsLink vertical padding
--s-button-font-weightLink font weight
--s-textActive/hovered link color
--s-text-mutedInactive link color
--s-surfaceIndicator background
--s-borderIndicator border color
--s-border-styleIndicator border style
--s-duration-fastTransition speed
--s-ease-outTransition easing