shadcn.io is an independent project built on shadcn/ui
On this page9 sections
Motion Highlight puts one background behind a set of items and slides it to the item under the pointer, or to the chosen one, taking that item's size on the way. Use it behind nav links, the rows of a menu or a grid of cards, where a separate hover color per item would blink from one to the next.
It only draws. For a short row where exactly one option is picked, a Segment Group is the dedicated control, and Tabs fit when each option shows its own panel.
Installation
Anatomy

Usage
import {
MotionHighlight, MotionHighlightItem,
} from "@/components/ui/motion-highlight";Every item needs a value. It carries data-highlighted while the highlight sits behind it and data-active while it is the chosen one, so a class such as data-highlighted:text-foreground darkens the text the highlight is under.
<MotionHighlight hover>
<MotionHighlightItem asChild value="home">
<button type="button">Home</button>
</MotionHighlightItem>
<MotionHighlightItem asChild value="about">
<button type="button">About</button>
</MotionHighlightItem>
</MotionHighlight>Accessibility
The highlight is a span hidden with aria-hidden, and the component adds no role, no state and no keys of its own. Tab moves through the items as the buttons or links they are, and with hover the highlight follows keyboard focus the way it follows the pointer. The chosen item is marked only by the highlight, so tell screen readers yourself: aria-pressed on toggle buttons, as the Tabs demo does, or aria-current on the link to the current page, as the nav at the top of this page does.
Demos
Tabs
A Day, Week, Month and Year range picker without hover, so the highlight marks the chosen range only and moves when another is clicked. highlightClassName makes it a raised pill on a muted track, each button sets aria-pressed, and a line underneath reads Revenue by week. Use it for a view switch whose value drives something else on the page.
List
Five actions in a popover-style column, Rename through Move to trash, each with its shortcut. With hover on, the accent highlight follows the pointer and keyboard focus from row to row, and since the rows share one width, only its vertical position changes. Clicking a row also makes it the chosen one, so the highlight rests there once the pointer leaves.
Cards
Four guide links, Getting started, Theming, Blocks and Components, in a grid of two columns from the small breakpoint up. The highlight crosses rows and columns and takes each card's size, which a sliding underline can't do. Keep each card a single link, as here, so the highlight covers exactly what a click opens.
FAQ
What's the difference between hover and click in Motion Highlight?
With hover, the highlight follows the pointer and keyboard focus, goes back to the chosen item when they leave, and fades out after a short pause if nothing is chosen.
Without it, the highlight marks the chosen item only and moves when another is clicked, as in the Tabs demo. Either way, a click makes that item the chosen one.
How do I control the chosen item in Motion Highlight with React?
Keep the chosen value in state, pass it as value on MotionHighlight and update it in onValueChange, which receives the clicked item's value as a string. The Tabs demo does this to print the range under the picker.
To choose an item at the start and let the component keep its own state, set defaultValue instead. Clicking the chosen item again reports it again and never clears it.
How do I style the Motion Highlight background?
Pass highlightClassName to MotionHighlight. It is merged over the default rounded-md bg-muted, so rounded-full bg-primary/10, or bg-background shadow-sm as in the Tabs demo, replaces it.
The highlight sits behind the items, so an item with a background of its own hides it. Style the items' text and icons through data-highlighted: and data-active: classes instead.
Should MotionHighlightItem wrap my button or become it?
Pass asChild, and the item becomes your button or link, so the highlight is measured on the element people click and the data attributes land on it.
Without it, the item is a div around its content, and the highlight is measured on that wrapper rather than on the element that takes focus and clicks. That works for a block with nothing interactive inside.
How do I add my own click handler to a Motion Highlight item?
Put onClick on MotionHighlightItem, not on the element inside it. With asChild, the item's own onClick, onFocus, onBlur, onPointerEnter and onPointerLeave replace the child's, so a handler on the button never runs. On the item, each of those five of yours runs first and the item's own after it, so a click still makes the item the chosen one.
When all you need is the chosen value, read it from the change callback on MotionHighlight instead.
How do I disable an item in Motion Highlight?
Set disabled on MotionHighlightItem and on the button inside it. The item's disabled keeps the highlight off it, stops a click from choosing it and adds data-disabled for your styles, but it never reaches the element, which stays focusable and clickable.
The button's own disabled takes it out of the tab order and makes screen readers announce it as unavailable.
Does Motion Highlight work in a grid or a scrolling list?
Yes. Each item is measured by its layout position inside MotionHighlight, so rows, columns, grids and items of different sizes all work, and a ResizeObserver measures again when the root or an item changes size.
For a list that scrolls, make MotionHighlight the scrolling element or put it inside the one that scrolls, so the highlight moves with the items. Nothing listens for scrolling, so with a scroller between them the items scroll away while the highlight stays where it was.
What does Motion Highlight do when someone prefers reduced motion?
The highlight jumps to its item instead of sliding and resizing, and appears and disappears without a fade. Every transition on it is turned off under motion-reduce, so the change is immediate.
It still marks the same item at the same moments, so hover, focus and the chosen state read exactly as they do with motion. Your own item styles keep their transitions unless you add motion-reduce:transition-none, as the Tabs demo does.
API Reference
MotionHighlight
value?string
The item highlighted at rest, when controlled.
defaultValue?string
The item highlighted at rest, at first, when uncontrolled.
onValueChange?(value: string) → void
Called with an item's value when it's chosen (clicked).
- Parameters
value– string- Returns
void
highlightClassName?string
Classes for the highlight itself (rounded-md bg-muted by default).
hover?boolean
Whether the highlight follows the pointer and keyboard focus. Without it the highlight marks the chosen item only, and moves on a click.
- Default
false
className?string
Merged with the part's classes.
--motion-highlight-heightstring--motion-highlight-widthstring--motion-highlight-xstring
The highlight's place, set from its item.
--motion-highlight-ystringMotionHighlightItem
<div> data-slot="motion-highlight-item"
valuestring
The item's value: the highlight's value when it's chosen.
disabled?boolean
Whether the item is skipped: never highlighted or chosen.
- Default
false
asChild?boolean
Use the provided child element as the default rendered element, combining their props and behavior.
data-active?stringdata-disabled?string
Present when disabled is true.
data-highlighted?stringdata-value?string
Mirrors value.
--motion-highlight-xstring
The highlight's place, set from its item.











