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.

Component 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.

classes

Override or extend the styles applied to the component.

See CSS API below for more details.

Type:object


defaultValue

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

Type:number

Default:null


disabled

If true, the component is disabled.

Type:bool

Default:false


emptyIcon

The icon to display when empty.

Type:node

Default:<StarBorder fontSize="inherit" />


emptyLabelText

The label read when the rating input is empty.

Type:node

Default:'Empty'


getLabelText

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.

Type:func

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

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

highlightSelectedOnly

If true, only the selected icon will be highlighted.

Type:bool

Default:false


icon

The icon to display.

Type:node

Default:<Star fontSize="inherit" />


IconContainerComponent

The component containing the icon.

Type:elementType

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


max

Maximum rating.

Type:number

Default:5


name

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.

Type:string


onChange

Callback fired when the value changes.

Type:func

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

onChangeActive

Callback function that is fired when the hover state changes.

Type:func

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

precision

The minimum increment value change allowed.

Type:number

Default:1


readOnly

Removes all hover effects and pointer events.

Type:bool

Default:false


size

The size of the component.

Type:'small'
| 'medium'
| 'large'
| string

Default:'medium'


sx

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

See the `sx` page for more details.

Type:Array<func
| object
| bool>
| func
| object


value

The rating value.

Type:number


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.

.Mui-disabledSTATE

State class applied to the root element if disabled={true}.


.Mui-focusVisibleSTATE

State class applied to the root element if keyboard focused.


.Mui-readOnlySTATE

Styles applied to the root element if readOnly={true}.


.MuiRating-decimal

Styles applied to the icon wrapping elements when decimals are necessary.

Rule name:decimal


.MuiRating-icon

Styles applied to the icon wrapping elements.

Rule name:icon


.MuiRating-iconActive

Styles applied to the icon wrapping elements when active.

Rule name:iconActive


.MuiRating-iconEmpty

Styles applied to the icon wrapping elements when empty.

Rule name:iconEmpty


.MuiRating-iconFilled

Styles applied to the icon wrapping elements when filled.

Rule name:iconFilled


.MuiRating-iconFocus

Styles applied to the icon wrapping elements when focus.

Rule name:iconFocus


.MuiRating-iconHover

Styles applied to the icon wrapping elements when hover.

Rule name:iconHover


.MuiRating-label

Styles applied to the label elements.

Rule name:label


.MuiRating-labelEmptyValueActive

Styles applied to the label of the "no value" input when it is active.

Rule name:labelEmptyValueActive


.MuiRating-root

Styles applied to the root element.

Rule name:root


.MuiRating-sizeLarge

Styles applied to the root element if size="large".

Rule name:sizeLarge


.MuiRating-sizeMedium

Styles applied to the root element if size="medium".

Rule name:sizeMedium


.MuiRating-sizeSmall

Styles applied to the root element if size="small".

Rule name:sizeSmall


.MuiRating-visuallyHidden

Visually hide an element.

Rule name:visuallyHidden



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

Edit this page

Was this page helpful?


RadioGroupScopedCssBaseline

Blog

Store