Rating
Introduction
Section titled “Introduction”Picks a score on a short scale of stars or a custom symbol: performance reviews, feedback, product quality. Half steps are optional, the rating can be cleared, and three sizes are available. display: true shows an existing score as a non-interactive image whose name reads like “Customer rating: 4.5 of 5”. The interactive control follows the WAI-ARIA APG slider pattern (one tab stop). Rating is a Form control: it validates, serializes, and resets with Form, and native forms receive a hidden input.
- Half stepsWhole or half symbols, by pointer half or arrow keys, filled in the reading direction.
- One tab stopThe APG slider pattern: arrows, Page, Home, End, and digit keys, announced as "3.5 of 5".
- Display modeA non-interactive image with the same text for tables and cards.
- Your symbolStars by default, or any icon; captions such as "Meets expectations" per step.
- Form readyRequired, custom validation, clearable, and a hidden input for native forms.
Use it for
- Subjective scores on a short scale: performance reviews, feedback, product quality.
- Showing an existing score in a list or a card (display mode).
Use something else for
- Scales longer than 10 or values that need precision: use Slider or Number Input.
- Named choices such as ‘Meets expectations’: use Radio Group (or Rating with labels and valueText when the scale is ordinal).
Anatomy
<div class="aui-field aui-rating aui-rating--md"> <label class="aui-field__label">Overall performance</label> <div class="aui-field__description">help</div> <div class="aui-rating__control" role="slider" tabindex="0" aria-valuemin="0" aria-valuemax="5" aria-valuenow="3.5" aria-valuetext="3.5 of 5"> <span class="aui-rating__item"><svg class="aui-rating__empty"/><span class="aui-rating__fill"><svg/></span></span> (x max) </div> <div class="aui-rating__caption" aria-hidden="true">Meets expectations</div> <div class="aui-field__error">error</div> <input type="hidden" name="score"></div>Live example
Section titled “Live example”Use the bar above each frame to switch theme, density, direction, and locale.
Rating in the Personal preferences showcase
Section titled “Rating in the Personal preferences showcase”The part of the Personal preferences showcase that uses Rating. Change its options, use it with the keyboard, and watch the event log; the link in the frame opens the full showcase. The bar above the frame switches theme, density, direction, and locale.
Showcase source
// Preferences showcase: a personal settings page with the new form controls. An accent// color with swatches, a contrast hint, and the eyedropper where supported; a satisfaction rating// with half steps; team assignment between two searchable lists (with drag); a work location// cascader whose cities load from a simulated server; a mention comment box with @people and// #tags from a simulated directory; a masked phone number; and an acknowledgement signature.import { Cascader, type CascaderOption, type CascaderValue } from '@absoluteui/components/cascader';import { ColorPicker } from '@absoluteui/components/color-picker';import { MaskedInput, MASK_PRESETS } from '@absoluteui/components/masked-input';import { MentionInput, type MentionSuggestion } from '@absoluteui/components/mention-input';import { Rating } from '@absoluteui/components/rating';import { SignaturePad } from '@absoluteui/components/signature-pad';import { TransferList, type TransferListItem } from '@absoluteui/components/transfer-list';import { action, choice, createShowcase, hostIn, section, status, toggle, wait } from './kit.js';
const sc = createShowcase({ title: 'Personal preferences', description: 'Pick an accent color, rate onboarding, choose your team and location, leave a comment with mentions, and sign.', simulated: true,});
// Appearance: color.const appearance = section(sc, 'Appearance', ['color-picker']);const color = ColorPicker.create(hostIn(appearance), { label: 'Accent color', description: 'Used for your calendar entries and highlights.', value: '#2563eb', presets: [ { value: '#2563eb', label: 'Blue' }, { value: '#15803d', label: 'Green' }, { value: '#b45309', label: 'Amber' }, { value: '#b91c1c', label: 'Red' }, { value: '#7c3aed', label: 'Violet' }, ], recent: ['#0f766e', '#be185d'], contrastWith: '#ffffff', name: 'accent',});sc.listen(color.host, ['aui-change'], 'color');
// Feedback: rating.const feedback = section(sc, 'Feedback', ['rating']);const rating = Rating.create(hostIn(feedback), { label: 'How was your onboarding?', allowHalf: true, value: 4, labels: ['Poor', 'Fair', 'Good', 'Very good', 'Excellent'], name: 'onboarding',});sc.listen(rating.host, ['aui-change'], 'rating');Rating.create(hostIn(feedback), { label: 'Team average', value: 4.5, allowHalf: true, display: true, size: 'sm' });
// Team: transfer list over a realistic directory size.const team = section(sc, 'Team', ['transfer-list']);const FIRST = ['Ana', 'Ben', 'Chen', 'Divya', 'Elif', 'Farah', 'Goran', 'Hana', 'Ivan', 'Jun', 'Kofi', 'Lena', 'Mateo', 'Nora', 'Omar', 'Priya'];const LAST = ['Ruiz', 'Okafor', 'Wang', 'Iyer', 'Kaya', 'Haddad', 'Petrov', 'Sato', 'Novak', 'Kim', 'Mensah', 'Fischer', 'Silva', 'Berg', 'Aziz', 'Rao'];const people: TransferListItem[] = [];for (let i = 0; i < 240; i++) { const name = `${FIRST[i % FIRST.length] ?? ''} ${LAST[Math.floor(i / FIRST.length) % LAST.length] ?? ''}`; people.push({ value: `p${String(i)}`, label: name, description: ['Engineering', 'Finance', 'People', 'Sales'][i % 4] ?? '', ...(i % 37 === 5 ? { disabled: true } : {}) });}const transfer = TransferList.create(hostIn(team), { label: 'Project team', items: people, value: ['p1', 'p2'], draggable: true, maxSelected: 12, name: 'team' });sc.listen(transfer.host, ['aui-change'], 'team');
// Location: lazy cascader.const location = section(sc, 'Work location', ['cascader']);const CITIES: Record<string, string[]> = { 'de/by': ['Munich', 'Nuremberg', 'Augsburg'], 'de/be': ['Berlin'], 'in/ka': ['Bengaluru', 'Mysuru'], 'in/mh': ['Mumbai', 'Pune'], 'us/ca': ['San Francisco', 'Los Angeles', 'San Diego'], 'us/ny': ['New York', 'Buffalo'],};const places: CascaderOption[] = [ { value: 'de', label: 'Germany', children: [{ value: 'by', label: 'Bavaria' }, { value: 'be', label: 'Berlin' }] }, { value: 'in', label: 'India', children: [{ value: 'ka', label: 'Karnataka' }, { value: 'mh', label: 'Maharashtra' }] }, { value: 'us', label: 'United States', children: [{ value: 'ca', label: 'California' }, { value: 'ny', label: 'New York' }] },];const cascader = Cascader.create(hostIn(location), { label: 'Office', options: places, value: ['de', 'by', 'munich'], levelLabels: ['Country', 'State', 'City'], name: 'office', loadChildren: async (_option, { signal, path }) => { await wait(500, signal); sc.log('server answered', { path }); return (CITIES[path.join('/')] ?? []).map((city) => ({ value: city.toLowerCase().replace(/\s+/g, '-'), label: city, isLeaf: true })); },});sc.listen(cascader.host, ['aui-change'], 'cascader');
// Comment: mentions from a simulated directory.const comment = section(sc, 'Comment', ['mention-input']);const TAGS = ['onboarding', 'payroll', 'benefits', 'equipment', 'training'];const findPeople = async (query: string, signal: AbortSignal): Promise<MentionSuggestion[]> => { await wait(250, signal); const q = query.toLowerCase(); return people.filter((p) => p.label.toLowerCase().includes(q)).slice(0, 8).map((p) => ({ id: p.value, label: p.label, description: p.description ?? '' }));};const mention = MentionInput.create(hostIn(comment), { label: 'Note for your manager', description: 'Type @ to mention a colleague or # to add a topic.', maxLength: 500, showCounter: true, name: 'note', triggers: [ { char: '@', label: '@ for people', provider: (query, { signal }) => findPeople(query, signal) }, { char: '#', label: '# for topics', provider: async (query, { signal }) => { await wait(150, signal); return TAGS.filter((t) => t.startsWith(query.toLowerCase())).map((t) => ({ id: t, label: t })); } }, ],});sc.listen(mention.host, ['aui-change', 'aui-mention'], 'mention');
// Contact: masked phone number.const contact = section(sc, 'Contact', ['masked-input']);const phone = MaskedInput.create(hostIn(contact), { label: 'Mobile phone', name: 'phone', ...MASK_PRESETS.phoneUs });sc.listen(phone.host, ['aui-change'], 'phone');
// Acknowledgement: signature.const sign = section(sc, 'Acknowledgement', ['signature-pad']);const signature = SignaturePad.create(hostIn(sign), { label: 'Signature', description: 'Draw your signature, or choose Type to enter your full name.', required: true, name: 'signature' });sc.listen(signature.host, ['aui-change'], 'signature');const summary = status(sign);const summarize = (): void => { const v = signature.value; summary.textContent = v === null ? 'Not signed yet.' : v.mode === 'type' ? `Signed as ${v.text}.` : `Signed with ${String(v.strokes.length)} strokes.`;};signature.host.addEventListener('aui-change', summarize);summarize();
// Options.const controls = [color, rating, transfer, cascader, mention, phone, signature];toggle(sc, 'Disabled', false, (disabled) => { for (const c of controls) c.update({ disabled });});toggle(sc, 'Read-only', false, (readOnly) => { for (const c of controls) c.update({ readOnly });});choice( sc, 'Color picker', [ { value: 'popup', label: 'Popup' }, { value: 'inline', label: 'Inline' }, ], 'popup', (mode) => { color.update({ mode }); }, ['color-picker'],);toggle(sc, 'Half stars', true, (allowHalf) => { rating.update({ allowHalf });}, ['rating']);/** A single path (strings), as opposed to a list of paths. */const isPath = (v: CascaderValue): v is readonly string[] => v?.every((part) => typeof part === 'string') === true;toggle(sc, 'Several offices', false, (multiple) => { const current = cascader.value; cascader.update({ multiple, value: multiple ? (isPath(current) ? [current] : []) : null });}, ['cascader']);action(sc, 'Validate', () => { const invalid = controls.filter((c) => !c.reportValidity()); sc.log('validate', { invalid: invalid.map((c) => c.label) });});action(sc, 'Reset', () => { for (const c of controls) c.reset(); summarize(); sc.log('reset');});Performance score with half steps and captions
Section titled “Performance score with half steps and captions”import { Rating, type RatingValueDetail } from '@absoluteui/components/rating';
const host = document.createElement('div');const out = document.createElement('p');document.body.append(host, out);Rating.create(host, { label: 'Overall performance', allowHalf: true, required: true, labels: ['Needs improvement', 'Developing', 'Meets expectations', 'Exceeds expectations', 'Outstanding'],});host.addEventListener('aui-change', (event) => { const { value } = (event as CustomEvent<RatingValueDetail>).detail; out.textContent = value === null ? 'Not rated' : `Score ${String(value)}`;});Read-only display in a list
Section titled “Read-only display in a list”import { Rating } from '@absoluteui/components/rating';
const host = document.createElement('span');document.body.append(host);Rating.create(host, { label: 'Customer rating', value: 4.5, allowHalf: true, display: true, size: 'sm', hideLabel: true });Custom symbol and value text
Section titled “Custom symbol and value text”import { Rating } from '@absoluteui/components/rating';
const host = document.createElement('div');document.body.append(host);Rating.create(host, { label: 'Difficulty', max: 3, value: 2, icons: { item: 'alert-triangle' }, valueText: (v, max) => `Level ${String(v)} of ${String(max)}`,});Install and start
Section titled “Install and start”npm install @absoluteui/components @absoluteui/core @absoluteui/themeRegistry setup, the theme stylesheet, and the Content Security Policy are covered in Installation.
import { Rating } from '@absoluteui/components/rating';import '@absoluteui/components/rating/style.css';First use
Section titled “First use”import { Rating } from '@absoluteui/components/rating';import '@absoluteui/components/rating/style.css';
const host = document.querySelector<HTMLElement>('#quality');if (host) Rating.create(host, { label: 'Quality', value: 4, name: 'quality' });More usage
import { Rating, type RatingValueDetail } from '@absoluteui/components/rating';
const host = document.querySelector<HTMLElement>('#score');if (host) { Rating.create(host, { label: 'How was onboarding?', allowHalf: true, labels: ['Poor', 'Fair', 'Good', 'Very good', 'Excellent'] }); host.addEventListener('aui-change', (event) => { const { value } = (event as CustomEvent<RatingValueDetail>).detail; console.log(value); });}Using Angular? See Rating for Angular.
API reference
Section titled “API reference”Factory
Section titled “Factory”Rating.create(host: HTMLElement, options: RatingOptions): RatingGlobal configuration key: rating (see Configuration).
Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
label |
string |
Visible label (required accessible name). Required. | |
hideLabel |
boolean |
"false" |
Visually hide the label. |
description |
string |
Help text, referenced by the control. | |
max |
number |
"5" |
Number of symbols, 1 to 10. |
value |
RatingValue |
"null" |
The score, or null for no rating; rounded to the step. |
allowHalf |
boolean |
"false" |
Allow half steps. |
clearable |
boolean |
"true" |
Choosing the current value again, Delete, Backspace, or 0 clears the rating. |
required |
boolean |
"false" |
A rating must be given. |
disabled |
boolean |
"false" |
Disable the control. |
readOnly |
boolean |
"false" |
Focusable and announced, but not changeable. |
display |
boolean |
"false" |
Non-interactive display (role=img with the value text). |
valueText |
(value: number, max: number) => string |
Full value text; default ‘{value} of {max}’. | |
labels |
readonly string[] |
Visible caption per whole step, such as ‘Good’. | |
name |
string |
Form field name (hidden input; empty when no rating). | |
validate |
(value: RatingValue) => string | null |
Consumer validation; return a message to mark the value invalid. | |
icons |
Partial<RatingIcons> |
Scale symbol (item) and validation icon (error). | |
size |
RatingSize |
"md" |
Symbol size: ‘sm’, ‘md’, or ‘lg’. Globally configurable. |
validationTiming |
ValidationTiming |
"blur" |
When validation messages appear. Globally configurable. |
locale |
string |
"en-US" |
Locale of the value text and messages. Globally configurable. Inherited from common configuration. |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
host |
HTMLElement |
The host element. |
value |
RatingValue |
The score, or null. |
validity |
FieldValidity |
Current validity. |
options |
Readonly<RatingOptions> |
Current options. |
Methods
Section titled “Methods”| Method | Description |
|---|---|
setValue(value: RatingValue): void |
Set the value, rounded and clamped (no event). |
setCustomError(message: string | null): void |
Show or clear an external error. |
reportValidity(): boolean |
Show messages now and return validity. |
focus(): void |
Focus the control. |
reset(): void |
Restore the initial value and clear the validation state. |
update(options: Partial<RatingOptions>): void |
Merge and apply options. |
destroy(): void |
Remove rendering, listeners, and the form registration. |
Events
Section titled “Events”| Event | Detail | Bubbles | Cancelable | Description |
|---|---|---|---|---|
aui-change |
RatingValueDetail |
Yes | No | The user changed the score: { value, validity }. |
aui-hover |
RatingHoverDetail |
No | No | The pointer previews a value (null when it leaves): { value }. |
CSS classes
Section titled “CSS classes”All rules live in the aui.components cascade layer, so application styles override them without specificity battles.
| Class | Purpose |
|---|---|
aui-rating |
Host (with aui-field). |
aui-rating--sm | --md | --lg |
Size. |
aui-rating--display | --readonly | --disabled | --invalid |
State modifiers. |
aui-rating__control |
The slider (or image in display mode). |
aui-rating__item |
One symbol. |
aui-rating__empty |
Outline symbol. |
aui-rating__fill |
Solid symbol clipped to the filled part. |
aui-rating__fill--outline |
Filled copy of an icon without a solid variant (the outline is filled). |
aui-rating__item--preview |
Symbol while the pointer previews a value. |
aui-rating__caption |
Visible caption from labels (aria-hidden). |
Icon slots
Section titled “Icon slots”| Slot | Default icon |
|---|---|
item |
star (icon set) |
error |
alert-circle |
Design tokens
Section titled “Design tokens”Tokens this stylesheet reads (verified in CI). Override them in a theme or with the Theme Designer.
--aui-color-border-strong | --aui-color-error-fg | --aui-color-focus-ring | --aui-color-text | --aui-color-text-disabled | --aui-color-text-muted | --aui-color-warning-fg | --aui-duration-fast | --aui-easing-standard | --aui-focus-ring-offset | --aui-focus-ring-width | --aui-font-family-sans | --aui-font-size-sm | --aui-font-weight-medium | --aui-icon-size-lg | --aui-icon-size-md | --aui-icon-size-sm | --aui-line-height-tight | --aui-radius-sm | --aui-space-1
TypeScript definitions
type RatingValue = number | null;type RatingSize = 'sm' | 'md' | 'lg';interface RatingConfig { validationTiming: ValidationTiming; size: RatingSize }interface RatingIcons { item: IconRef; error: IconRef }interface RatingOptions extends Partial<RatingConfig> { label: string; hideLabel?: boolean; description?: string; max?: number; value?: RatingValue; allowHalf?: boolean; clearable?: boolean; required?: boolean; disabled?: boolean; readOnly?: boolean; display?: boolean; valueText?: (value: number, max: number) => string; labels?: readonly string[]; name?: string; validate?: (value: RatingValue) => string | null; locale?: string; icons?: Partial<RatingIcons>;}interface RatingValueDetail { value: RatingValue; validity: FieldValidity }interface RatingHoverDetail { value: RatingValue }Accessibility and performance
Section titled “Accessibility and performance”Accessibility
Section titled “Accessibility”Pattern: WAI-ARIA APG Slider: one focusable role=slider with aria-valuenow, aria-valuemin (0 when clearable), aria-valuemax, and aria-valuetext such as ‘3.5 of 5’. Chosen over the radio group pattern because half steps and clearing are one value on a range and the control is a single tab stop. Display mode is role=img named by the label and the value text.
Checked on every docs build: the showcase passes axe (WCAG 2.2 A and AA rules) in the default, dark, and high-contrast themes and right to left; the playground loads without errors and passes axe before and after every on/off option is switched, with no Content Security Policy violations.
Keyboard
Section titled “Keyboard”| Key | Context | Action |
|---|---|---|
| ArrowRight / ArrowUp | Control | Increase by one step (ArrowLeft increases in right-to-left). |
| ArrowLeft / ArrowDown | Control | Decrease by one step. |
| Page Up / Page Down | Control | Increase or decrease by one whole symbol. |
| Home / End | Control | Lowest value (no rating when clearable) or the maximum. |
| 1 to 9 | Control | Set that many symbols (up to max). |
| 0 / Delete / Backspace | Control (clearable) | Clear the rating. |
| Element | Role |
|---|---|
| control | slider (img in display mode) |
| symbols and caption | none (decorative; the control announces the value) |
ARIA attributes
Section titled “ARIA attributes”| Attribute | Element | Value |
|---|---|---|
aria-labelledby |
control | the visible label |
aria-valuemin / aria-valuemax |
control | 0 (or one step when not clearable) and max |
aria-valuenow / aria-valuetext |
control | the score and its text (‘3.5 of 5’, ‘No rating’, or valueText) |
aria-required |
control | true when required |
aria-readonly |
control | true when read-only |
aria-disabled |
control | true when disabled (also removed from the tab order) |
aria-invalid / aria-describedby |
control | validation state; help text and error |
aria-label |
control (display mode) | ‘{label}: {value text}’ |
One tab stop; clicking a symbol focuses the control. Display mode is not focusable.
WCAG 2.2 success criteria addressed
Section titled “WCAG 2.2 success criteria addressed”| Criterion | Level | Note |
|---|---|---|
| 1.1.1 Non-text Content | A | |
| 1.3.1 Info and Relationships | A | |
| 1.4.1 Use of Color | A | |
| 1.4.11 Non-text Contrast | AA | |
| 2.1.1 Keyboard | A | |
| 2.5.8 Target Size (Minimum) | AA | |
| 4.1.2 Name, Role, Value | A |
Automated test results: Accessibility and compliance.
Notes and known caveats
Section titled “Notes and known caveats”- Filled and empty symbols differ in shape (solid and outline), not only in color (WCAG 1.4.1).
- Each symbol is at least 24 by 24 CSS pixels (WCAG 2.5.8).
- Clearing announces ‘Rating cleared’ through the polite live region.
- Manual screen-reader verification (NVDA, JAWS, VoiceOver) is pending.
Performance
Section titled “Performance”| Import cost | Minified | gzip | brotli | CSS brotli |
|---|---|---|---|---|
@absoluteui/components/rating |
45.4 kB | 15.4 kB | 13.7 kB | 0.9 kB |
Measured at build time, including every AbsoluteUI module the component pulls in. No third-party runtime dependencies.
| Budget (enforced in CI) | Limit |
|---|---|
| Rating.create, per instance | < 2 ms average in headless Chromium |
Tested scale: 1 to 10 symbols; hundreds of display-mode instances in a table.
Symbols are rendered once per max and icon; value changes only update a CSS custom property per symbol and the ARIA attributes.
Measured run times: Performance.
Details
Section titled “Details”States
Empty (no rating); rated; half step; hover preview; display; read-only; disabled; required; invalid; sizes sm, md, lg.
State transitions
| From | Trigger | To |
|---|---|---|
| any | click a symbol | that value (the left half gives a half step with allowHalf); aui-change |
| rated | click the current value (clearable) | no rating; “Rating cleared” announced |
| any | arrow, Page, Home, End, or digit | new value; aui-change |
| any | pointer over a symbol | preview fill and caption; aui-hover |
| preview | pointer leaves | the committed value |
Accessibility notes
- APG slider pattern rather than a radio group: half steps and clearing are one value on a range, and the control is a single tab stop.
- Filled and empty symbols differ in shape (solid and outline), not only in color (WCAG 1.4.1).
- Each symbol is at least 24 by 24 CSS pixels (WCAG 2.5.8).
- Manual screen-reader verification is pending.
Responsive behavior
The control is as wide as its symbols; sizes follow icon-size-sm|md|lg with a minimum 24px target.
Right-to-left
Symbols run right to left, half symbols fill from the right (logical clipping), and ArrowLeft increases.
Theming
Fill, outline, and focus colors are in the contrast gate. Forced colors use Highlight for filled symbols, CanvasText for outlines, and GrayText when disabled.
Global configuration
configureAbsoluteUI({ components: { rating: { size: 'lg', validationTiming: 'submit' } } });Component configuration
Instance size, validationTiming, and locale override configuration; configuration changes re-render existing ratings.
Icons
icons.item replaces the star (default: the icon set’s star, outline and solid variants). Icons without a solid variant are filled by the stylesheet. icons.error replaces the validation icon.
Security
Labels, captions, and value text use textContent. Fill widths are set through the CSSOM, so a strict CSP without unsafe-inline styles works.
Data handling
No persistence, network access, or telemetry.
Supported data scale
1 to 10 symbols; hundreds of display-mode instances in a table.
Edge cases
value: 3.7rounds to 3.5 withallowHalf, otherwise to 4;value: 0means no rating.- With
clearable: false, the lowest keyboard value is one step and Delete does nothing. - Reducing
maxbelow the value clamps the value. - Touch input does not show a hover preview; a tap commits.
Errors
| Code | Category | Cause |
|---|---|---|
RATING_OPTIONS |
configuration | Blank label, max outside 1 to 10, a non-finite value, or a non-function valueText / validate, or non-string labels. |
CFG_INVALID_VALUE / CFG_UNKNOWN_OPTION |
configuration | Invalid configuration. |
Invalid options throw before the host is modified; an invalid update() leaves the previous state intact.
Known limitations
- At most 10 symbols; half steps are the finest granularity.
- Manual screen-reader verification is pending.
Unsupported scenarios
- Arbitrary fractions such as 3.7 (values round to the step).
- A different icon per position.
(c) 2026 Kasadara Technology Solutions Pvt Ltd. AbsoluteUI is free to use under the AbsoluteUI Free Use License; it is not open source.