ba-star-rating
A component for presenting a star rating out of 5
Airframe
Web Components
React
React Native
Anatomy
Star icons
A row of five star icons that fill, half-fill, or remain empty to visually represent the rating out of 5. The icons are decorative and hidden from assistive technology
Rating text
The supportive text showing the numeric rating out of 5 (e.g. "2.5/5"), which conveys the rating to assistive technology
Design Documentation
ba-star-rating is a presentational component for displaying a rating out of 5. Pass the value through the rating attribute. It is not an interactive control, so do not use it to capture or collect a rating from the user.
Use the size attribute to set the star size to either 12 or 16. Pick the size that aligns with the scale and density of the content around the rating so the stars sit comfortably alongside nearby text.
The rating value should be one of the supported half-star increments: 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5 or 5. Values outside this range or between increments will not render as intended.
Live Demo
<ba-star-rating rating="2.5"></ba-star-rating>
Properties and attributes
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
rating(required) |
rating |
Value out of 5 to display | string |
undefined |
size |
size |
Size of the stars in the star rating | "12" | "16" | undefined |
'12' |
Permitted ARIA roles
- None
Slots
No slotted content available for this component.
Parent components
ba-star-rating can be slotted into:
Usage
Basic usage
The star rating component is used to display a rating out of 5. The rating is passed as a string to the rating attribute.
<ba-star-rating rating="3"></ba-star-rating>
Half-star ratings
Ratings support half-star increments, so values such as 2.5 render a half-filled star.
<ba-star-rating rating="2.5"></ba-star-rating>
Setting the star size
Use the size attribute to set the star size to either 12 or 16 to suit the surrounding content.
<ba-star-rating rating="4" size="16"></ba-star-rating>
Guidelines
The ba-star-rating element does not contain any elements that assistive technology would recognise as clickable. It is purely presentational and should be treated as such.
Keyboard navigation
No keyboard interactions have been defined for this component.
Usage and accessibility checklist
Use this checklist to confirm the component has been configured and used correctly.
UX checklist
- ba-star-rating is only used to present a rating out of 5 and not as an interactive control for capturing a rating
- The rating value is one of the supported increments (0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5)
- The size attribute is set to either 12 or 16 to match the surrounding content
Accessibility checklist
- ba-star-rating has discernible, supportive text that communicates the rating out of 5
- Click or interaction events are not added to ba-star-rating as it is presentational only
These checks are handled by the component and do not need to be repeated each time it is used.
- Star icons are decorative and hidden from screen readers, with the rating text always present
- Rating is accessible to assistive technologies through the supportive text
- Colour contrast for the rating text and stars in all BAgel themes
- High contrast mode adjustments