Skip to content

Rating

import { Rating } from '@delightstack/components';
View code
<Rating value={0} />
View code
<Rating value={0} tooltip="Rate this item" />

Set precision={0.5} to allow half-star selections. The left half of each star registers a 0.5 increment.

3.5
View code
<Rating value={3.5} precision={0.5} show_value />

Use readonly to show a rating without interaction. Ideal for displaying average ratings.

4.3
View code
<Rating value={4.3} readonly show_value />

Use color to override the fill color of the stars.

Custom color (error red)

2

Custom color (green)

4
View code
<script>
import { Rating } from '@delightstack/components';
let likes = $state(2);
</script>
<Rating bind:value={likes} max={3} color="var(--c-error, hsl(0 70% 55%))" show_value />
<Rating value={4} readonly color="hsl(140 60% 45%)" show_value />

Allow clicking the current rating again to clear it to 0.

View code
<Rating value={3} clearable />
View code
<Rating size="0" value={3} readonly />
<Rating size="1" value={3} readonly />
<Rating size="2" value={3} readonly />
<Rating size="3" value={3} readonly />
0

Rate out of 10

View code
<Rating bind:value={rating} max={10} show_value />
PropTypeDefaultDescription
valuenumber0Current rating, bindable
maxnumber5Maximum number of icons
precision0.5 | 11Half or whole icon precision
size'0' | '1' | '2' | '3''1'Icon size
readonlybooleanfalseDisplay only, no interaction
disabledbooleanfalseDisable input
colorstring''Override filled icon color (CSS value)
show_valuebooleanfalseShow numeric value beside icons
clearablebooleanfalseAllow clicking current rating to clear (set to 0)
tooltipstring''Tooltip text on hover
densebooleanfalseTighter spacing between icons
comfortablebooleanfalseMore spacing between icons
idstringautoElement ID
namestring''Form field name
classstring''Additional CSS classes
EventDetailDescription
onchange{ value: number }Rating changed
onhover{ value: number }Hovering over a rating value
  • Uses role="slider" pattern on the container
  • aria-valuenow, aria-valuemin, aria-valuemax set appropriately
  • aria-label="Rating" for screen readers
  • Keyboard navigation: Arrow Right/Up to increase, Arrow Left/Down to decrease, Home for 0, End for max
  • Focus ring visible on :focus-visible
  • Read-only mode prevents interaction but remains visible
  • Hidden <input type="hidden"> for form submission
  • Half-star precision uses CSS clip-path for clean visual rendering