We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

Rating Component

The Rating component provides an interactive star-based rating system with keyboard navigation, accessibility features, and form integration capabilities.

  • Check Circle

    Interactive Stars: Clickable star icons with hover effects

  • Check Circle

    Keyboard Navigation: Full keyboard support with arrow keys

  • Check Circle

    Form Integration: Works seamlessly with form submissions

  • Check Circle

    Accessibility: ARIA support and screen reader compatibility

Create a simple rating component:

<Rating />
<Rating buttonProps={{ size: 'sm' }} />
Rate your experience
<Rating label="Rate your experience" />
Product Rating *
<Rating
label="Product Rating"
required
name="product-rating"
/>
Pre-filled Rating
<Rating
label="Pre-filled Rating"
rating={3}
/>
Rating Component Props Extends <div> HTMLElement
Prop Type Description
buttonProps ComponentProps<typeof Button> Props for star buttons
label string Label text for the rating input
labelProps HTMLAttributesWithData<label> Props for the label element
name string Form field name
rating number Initial rating value (1-5)
required boolean Makes the rating required

The rating component provides a set of functions to interact with the rating:

Rating Component Functions
Function Type Description
set: rating (rating: number) => void Sets the rating value
get: rating () => number Returns the current rating value
reset () => void Resets the rating value to 0
Waiting for events to be emitted… (Click on the rating to see the events)
Rating Change Event
CustomEvent<{
id?: string;
name?: string;
rating: number;
}>;

The Rating component works seamlessly with forms as it has a hidden input that is used to store the rating value:

<form>
<Rating
name="user-rating"
required
label="How would you rate this?"
/>
<button type="submit">Submit Rating</button>
</form>

The Rating component supports full keyboard interaction:

Key Action
← / ↓ Move to previous star
→ / ↑ Move to next star
Space/Enter Select current star rating
Tab Move focus to next interactive element

Limited Time Launch Sale

Add interactive rating components to your website with our AstroJS starter template. Get started now!

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes