Xzero UI
Pro library

Rating

A simple, accessible way to capture a numeric opinion.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/rating
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/rating

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { Rating } from "@/components/xzero/rating/rating";

export function ReviewForm() {
  const [stars, setStars] = useState(0);
  return (
    <form>
      <Rating label="Overall experience" value={stars} onChange={setStars} name="rating" />
    </form>
  );
}

API reference

Rating

A star rating built as a radio group, with half stars, scrubbing, clearing, and a rolling value label.

PropTypeDefaultDescription
label (required)string–Visible label and accessible name of the group.
valuenumber–Controlled value. 0 means not rated.
defaultValuenumber0Initial value when uncontrolled.
onChange(value: number) => void–Receives the committed value; 0 means cleared.
maxnumber5Number of stars.
readOnlybooleanfalseRenders a static image with an aria-label instead of radios.
disabledbooleanfalseDisables interaction.
descriptionstring–Hint under the stars, linked with aria-describedby.
size"sm" | "md" | "lg""md"Star size.
allowHalfbooleanfalsePointer, touch, and arrow keys move in half stars.
allowClearbooleantrueChoosing the current value again clears it; Backspace and Delete clear from the keyboard.
showValuebooleantrueShows the word or number for the previewed value beside the stars.
valueLabelsreadonly string[]–One word per whole star. Five whole stars default to Poor through Excellent.
emptyLabelstring"Not rated"Shown when the value is 0.
namestring–Submits the value with a surrounding form via a hidden input.
classNamestring–Class on the field wrapper.

Keyboard interactions

KeysAction
ArrowRight / ArrowUpIncreases by one step (half a star with allowHalf).
ArrowLeft / ArrowDownDecreases by one step.
Home / EndJumps to the lowest or highest value.
1-9Sets that many stars.
Backspace / DeleteClears the rating when allowClear is on.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in toggles

Guidance for AI tools

Rating: A simple, accessible way to capture a numeric opinion. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components