Skip to content

Rating

Ratings provide insight regarding others' opinions and experiences, and can allow the user to submit a rating of their own.

Basic rating

ControlledRead onlyDisabledNo rating given
Press Enter to start editing

Rating precision

The rating can display any float number with the value prop. Use the precision prop to define the minimum increment value change allowed.

Press Enter to start editing

Hover feedback

You can display a label on hover to help the user pick the correct rating value. The demo uses the onChangeActive prop.

Poor+
Press Enter to start editing

Sizes

For larger or smaller ratings use the size prop.

Press Enter to start editing

Customization

Here are some examples of customizing the component. You can learn more about this in the overrides documentation page.

Custom icon and color10 stars
Press Enter to start editing

Radio group

The rating is implemented with a radio group, set highlightSelectedOnly to restore the natural behavior.

Press Enter to start editing

Accessibility

(WAI tutorial)

The accessibility of this component relies on:

  • A radio group with its fields visually hidden. It contains six radio buttons, one for each star, and another for 0 stars that is checked by default. Be sure to provide a value for the name prop that is unique to the parent form.
  • Labels for the radio buttons containing actual text ("1 Star", "2 Stars", …). Be sure to provide a suitable function to the getLabelText prop when the page is in a language other than English. You can use the included locales, or provide your own.
  • A visually distinct appearance for the rating icons. By default, the rating component uses both a difference of color and shape (filled and empty icons) to indicate the value. In the event that you are using color as the only means to indicate the value, the information should also be also displayed as text, as in this demo. This is important to match success Criterion 1.4.1 of WCAG2.1.
Good
Press Enter to start editing

ARIA

The read only rating has a role of "img", and an aria-label that describes the displayed rating.

Keyboard

Because the rating component uses radio buttons, keyboard interaction follows the native browser behavior. Tab will focus the current rating, and cursor keys control the selected rating.

The read only rating is not focusable.

API

See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.