Skip to content

Rating

A star rating out of five in halves, shown as an image or asked for with a native select.

<div data-mount="show" id="sample-show"></div>

Installation

// package.json: "capsomer": "github:DrDustinEdwards/capsomer#v0.152.2"
import "capsomer/tokens.css";
import "capsomer/base.css";
import "capsomer/rating.css";

Usage

<span class="cap-rating"><span role="img" aria-label="3.5 out of 5 stars" class="cap-rating-img">
  <span class="cap-rating-stars" data-half="7" aria-hidden="true"><span class="cap-rating-empty">☆☆☆☆☆</span><span class="cap-rating-fill">★★★★★</span></span>
</span><span class="cap-rating-note">(12 ratings)</span></span>

Examples

Sizes

<div data-mount="sizes" id="sample-sizes"></div>

Asked for

<div data-mount="input" id="sample-input"></div>

API reference

Rating

PropTypeRequiredDoes
valuenumberYes
childrenReactNodeWords after the stars ("(12 ratings)"), visible.
size"sm" | "default" | "lg"
classNamestring

RatingInput

PropTypeRequiredDoes
namestringYes
labelstringYes
defaultValuenumberHalf stars, 0 for none. Uncontrolled with defaultValue, controlled with value and onChange.
valuenumber
onChange(value: number) => void
noneLabelstringWords for "no rating" (the empty choice).
wholebooleanAllow only whole stars.
idstring

CSS variables

VariableDefault
--_fill0%
--_star1.1em

Parts and data attributes

ClassIs
.cap-ratingthe root
.cap-rating-controla part
.cap-rating-emptya part
.cap-rating-filla part
.cap-rating-imga part
.cap-rating-notea part
.cap-rating-starsa part
AttributeValues
data-half0 1 10 2 3 4 5 6 7 8 9
data-sizelg sm

Accessibility

KeyDoes
Arrow keys on the selectChange the rating
  • Forced colors: the fill is CanvasText and the outline GrayText.
  • Screen readers: no manual NVDA or VoiceOver run, by decision (2026-11-07); the automated browser checks and a front-end review stand in. Automated: see the site's Tests page.