Skip to content

Rating ​

A star rating control implementing the WAI-ARIA slider pattern: the star row is a single tab stop, arrows adjust the value, and click or drag selects a star. Supports half-star precision, clear-on-repress, readonly display, validation chrome, and HTML form integration.

Basic Usage ​

html
<ore-rating label="Product rating" value="3"></ore-rating>

Listen for changes:

html
<ore-rating id="rating" label="Rate this article"></ore-rating>

<script type="module">
  document.getElementById('rating').addEventListener('change', (e) => {
    console.log('Rating:', e.currentTarget.value);
  });
</script>

Half Stars ​

Set precision="0.5" to allow half steps. The leading half of a star selects n - 0.5, and the trailing half selects n: left to right in LTR and right to left in RTL. Arrow keys also step by half. Values set from code are snapped onto the grid.

Full width

Readonly Display ​

Use readonly to display a rating without allowing user interaction: useful for showing review averages. Prefer readonly over disabled for an existing score the user cannot change — it keeps aria-readonly instead of a disabled control.

Full width

Clearing ​

Interactive ratings are clearable by default: pressing the already-selected star again resets the rating to 0. Set clearable="false" to keep the current value sticky.

Full width

Label, Helper & Error ​

label renders a visible caption above the stars (an aria-label="Rating" fallback applies when it is omitted). helper and error render assistive text below; an error replaces the helper, tints the empty stars, and sets aria-invalid/aria-errormessage on the slider. Pass richer markup through the label, helper, and error slots.

Full width

Required ​

required marks the slider aria-required and blocks ancestor-form submission until at least one star is selected.

Colors ​

Without a color the stars use the default gold. A color re-themes the fill:

Full width

Sizes ​

Full width

Custom Max ​

Full width

Disabled ​

Full width

Localized Announcements ​

The screen-reader value text (aria-valuetext) defaults to English. Override it with the labels JS property:

js
rating.labels = {
  unrated: 'Nicht bewertet',
  value: (value, max) => `${value} von ${max} Sternen`,
};

API Reference ​

Attributes ​

AttributeTypeDefaultDescription
valuenumber0Current rating, snapped to precision
maxnumber5Total number of stars
precision1 | 0.51Selection granularity
clearablebooleantrueRe-pressing the selected star clears the rating
readonlybooleanfalseDisplay-only mode; keeps the value in reading order
requiredbooleanfalseRequires at least one star for form submission
disabledbooleanfalseDisables the rating
labelstring''Visible label above the stars
helperstringN/AHelper text below the stars (hidden by error)
errorstringN/AError text; invalidates the slider
namestringN/AForm field name
color'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'N/AFilled star color
size'sm' | 'md' | 'lg''md'Star size

JS Properties ​

PropertyTypeDefaultDescription
labels{ unrated?: string; value?: (value, max) => string }English defaultsaria-valuetext strings

Slots ​

SlotDescription
labelVisible label content (overrides label)
helperHelper text content (overrides helper)
errorError text content (overrides error)

Events ​

EventDetailDescription
input—Native-style event; read the new rating from event.target.value
change—Native-style event fired after every committed rating change

Parts ​

PartDescription
wrapperColumn with label, stars, assistive text
labelVisible label element
starsThe focusable slider row
starOne star cell
helperThe helper text element
errorThe error text element

CSS Custom Properties ​

PropertyDefaultDescription
--rating-star-sizevar(--size-7)Size of each star icon
--rating-color-emptyvar(--color-contrast-200)Color of unselected stars
--rating-color-filledvar(--color-star) (gold)Color of selected / hovered stars
--rating-gapvar(--size-0_5)Gap between stars

Accessibility ​

The rating follows the WAI-ARIA slider rating pattern. The star row is one focusable role="slider" with aria-valuemin="0", aria-valuemax from max, and aria-valuenow/aria-valuetext announcing the exact rating (or the unrated state). The accessible name comes from the visible label via aria-labelledby, falling back to aria-label="Rating". An active error sets aria-invalid and aria-errormessage; required sets aria-required.

Keyboard: ←/→ (and ↑/↓) adjust by precision, Home unsets the rating, End selects the maximum, Tab moves focus in and out as a single stop.

Selected stars are always rendered solid-filled while empty stars keep the outline, so the value reads by shape, not only by color. A short scale "pop" on the committed star is suppressed under prefers-reduced-motion. In forced-colors environments empty stars use ButtonText and the fill uses Highlight.

Vertical scrolling and pinch zoom remain available over the stars. Cancelling an interaction or switching to disabled or readonly ends the drag without reverting already selected values.

  • Slider: drag-based numeric value picker