Skip to content

Rating API

API reference docs for the React Rating component. Learn about the props, CSS, and other APIs of this exported module.

Demos

Import

import Rating from '@mui/material/Rating';
// or
import { Rating } from '@mui/material';

Learn about the difference by reading this guide on minimizing bundle size.

Props

Props of the native component are also available.

NameTypeDefaultDescription
classesobject-

Override or extend the styles applied to the component.

See CSS classes API below for more details.

defaultValuenumbernull

The default value. Use when the component is not controlled.

disabledboolfalse

If true, the component is disabled.

emptyIconnode<StarBorder fontSize="inherit" />

The icon to display when empty.

emptyLabelTextnode'Empty'

The label read when the rating input is empty.

getLabelTextfuncfunction defaultLabelText(value) { return `${value} Star${value !== 1 ? 's' : ''}`; }

Accepts a function which returns a string value that provides a user-friendly name for the current value of the rating. This is important for screen reader users.
For localization purposes, you can use the provided translations.

Signature:function(value: number) => string
  • value The rating label's value to format.
highlightSelectedOnlyboolfalse

If true, only the selected icon will be highlighted.

iconnode<Star fontSize="inherit" />

The icon to display.

IconContainerComponentelementTypefunction IconContainer(props) { const { value, ...other } = props; return <span {...other} />; }

The component containing the icon.

maxnumber5

Maximum rating.

namestring-

The name attribute of the radio input elements. This input name should be unique within the page. Being unique within a form is insufficient since the name is used to generated IDs.

onChangefunc-

Callback fired when the value changes.

Signature:function(event: React.SyntheticEvent, value: number | null) => void
  • event The event source of the callback.
  • value The new value.
onChangeActivefunc-

Callback function that is fired when the hover state changes.

Signature:function(event: React.SyntheticEvent, value: number) => void
  • event The event source of the callback.
  • value The new value.
precisionnumber1

The minimum increment value change allowed.

readOnlyboolfalse

Removes all hover effects and pointer events.

size'small'
| 'medium'
| 'large'
| string
'medium'

The size of the component.

sxArray<func
| object
| bool>
| func
| object
-

The system prop that allows defining system overrides as well as additional CSS styles.

See the `sx` page for more details.

valuenumber-

The rating value.

The ref is forwarded to the root element.

Theme default props

You can use MuiRating to change the default props of this component with the theme.

CSS classes

These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.

Class nameRule nameDescription
.Mui-disabledState class applied to the root element if disabled={true}.
.Mui-focusVisibleState class applied to the root element if keyboard focused.
.Mui-readOnlyStyles applied to the root element if readOnly={true}.
.MuiRating-decimaldecimalStyles applied to the icon wrapping elements when decimals are necessary.
.MuiRating-iconiconStyles applied to the icon wrapping elements.
.MuiRating-iconActiveiconActiveStyles applied to the icon wrapping elements when active.
.MuiRating-iconEmptyiconEmptyStyles applied to the icon wrapping elements when empty.
.MuiRating-iconFillediconFilledStyles applied to the icon wrapping elements when filled.
.MuiRating-iconFocusiconFocusStyles applied to the icon wrapping elements when focus.
.MuiRating-iconHovericonHoverStyles applied to the icon wrapping elements when hover.
.MuiRating-labellabelStyles applied to the label elements.
.MuiRating-labelEmptyValueActivelabelEmptyValueActiveStyles applied to the label of the "no value" input when it is active.
.MuiRating-rootrootStyles applied to the root element.
.MuiRating-sizeLargesizeLargeStyles applied to the root element if size="large".
.MuiRating-sizeMediumsizeMediumStyles applied to the root element if size="medium".
.MuiRating-sizeSmallsizeSmallStyles applied to the root element if size="small".
.MuiRating-visuallyHiddenvisuallyHiddenVisually hide an element.

You can override the style of the component using one of these customization options: