// preview in
saved for every page

Rating

Stars for giving a score, or for showing an average. Interactive, it behaves like a radio group; read-only, it is one image with a text name and supports half stars.

Built on Base UIPattern WAI-ARIA Radio GroupClient componentSource ↗
minimal · light · #3fa34d
readOnly
disabled

Installation

Set up Camaleo once (Installation), then import it. The skin you load draws the stars.

import { Rating } from "@camaleo/react";

Anatomy

Interactive, the root is a radio group with one radio per star. Read-only, the root is an image and each star is a plain shape.

★★★☆
[data-slot="rating"][data-slot="rating-item"] · [data-slot="rating-star"]star icon: [data-slot="icon"]

Examples

Every example is a real file you can copy. They all wear the skin, mode and brand from the bar above.

minimal · light · #3fa34d
How was your stay?

4.8 · 128 reviews

Read-only, with the number

readOnly turns the stars into one image named by getLabel. Print the average and the count next to it, so everyone can compare at a glance.

  • Trail running shoes

  • Merino base layer

  • Insulated bottle, 750 ml

Half values

Read-only, any fraction shows as a half star, so 4.5 and 3.5 look different. Interactive ratings take whole stars only.

Rate the delivery

Pick a star

With a caption

Pick a star. Words like "Good" or "Excellent" in the caption and in each star's name tell people what the score means.

Rate your order

Required in a review

Send without a star. Check the value on submit and show a FieldError; inside a Field the message is linked to the group.

Rate your last purchases

Trail running shoes

Merino base layer

Insulated bottle, 750 ml

Several on one screen

When a list has one rating per row, give each its own aria-label with the item's name, or a screen reader hears "Your rating" three times.

Rate this product

You can rate it once it is delivered, on Oct 31.

Disabled, with a reason

Say when rating opens. A row of grey stars with no explanation looks broken.

Sizes

Set --cml-star-size on the rating: small for lists and cards, large when the rating is the whole task.

In context

Ratings live in reviews, cards and follow-ups. These are whole pieces of UI you can copy, in the skin you picked.

Review your order

Order #48213 · delivered Oct 24

Your rating
Product reviewCard · Field · Rating · Textarea · Button
Bestseller

Ridgeline trail shoe

4.8 · 128 reviews

$129
Product cardCard · Badge · Rating · Button

How did Marina do?

Your chat about a late refund was closed today at 2:40 PM.

What helped?

Support feedbackCard · Rating · ChipGroup · Button

Guidelines

4.8 · 128 reviews

DoShow the number and the count.

"4.8 · 128 reviews" is precise, and tells people how much to trust it.

Don’tStars on their own.

Nobody can tell 4.6 from 4.8, and a single review looks as solid as a hundred.

DoFive stars for an opinion.

A short scale is quick to pick and easy to read back.

Don’tTen stars.

The difference between 6 and 7 means nothing, and the targets get small.

Props

PropTypeDefaultDescription
maxnumber5Number of stars.
valuenumber—The rating, when you control it. 0 means no star picked yet.
defaultValuenumber0The starting rating, when the component keeps its own state.
onValueChange((value: number) => void)—Called with the star number when people pick one.
getLabel(value, max) => string"{n} of {max}"Accessible name of each star and of the read-only image (translatable).
disabledbooleanfalseWhether the component should ignore user interaction.
readOnlybooleanfalseShows the value as stars (halves included) in one image, e.g. an average of 4.8.
requiredbooleanfalseWhether the user must choose a value before submitting a form.
namestring—Identifies the field when a form is submitted.

Inside a Field, the label names the group and disabled and name can come from there too. The other radio-group attributes pass through.

Styling hooks

Restyle it without forking: target the attributes, or set the tokens on a parent, a skin or the rating itself.

Attributes

data-slot"rating" · "rating-item" · "rating-star"
data-filledpresent on the stars up to the value
data-checkedpresent on the picked star
data-fillfull · half · empty (read-only stars)
data-readonlypresent on a read-only rating
data-disabledpresent when disabled

Tokens it reads

Color

--cml-accent-text--cml-border-control--cml-focus-offset--cml-focus-ring--cml-focus-width

Shape & size

--cml-radius-control

This component only

--cml-disabled-opacity--cml-star-color--cml-star-empty--cml-star-on-bg--cml-star-size
/* gold stars, only on product cards */
.product-card [data-slot="rating"] {
  --cml-star-color: var(--cml-warning);
}

Accessibility

TabMoves focus to the picked star (or the first one), and out of the rating.
→ / ↓Picks the next star.
← / ↑Picks the previous star.
SpacePicks the focused star.
Was this page helpful? · Edit this page on GitHub