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 of the native component are also available.
Name | Type | Default | Description |
---|---|---|---|
classes | object | - | Override or extend the styles applied to the component. See CSS classes API below for more details. |
defaultValue | number | null | The default value. Use when the component is not controlled. |
disabled | bool | false | If |
emptyIcon | node | <StarBorder fontSize="inherit" /> | The icon to display when empty. |
emptyLabelText | node | 'Empty' | The label read when the rating input is empty. |
getLabelText | func | function 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. Signature: function(value: number) => string
|
highlightSelectedOnly | bool | false | If |
icon | node | <Star fontSize="inherit" /> | The icon to display. |
IconContainerComponent | elementType | function IconContainer(props) { const { value, ...other } = props; return <span {...other} />; } | The component containing the icon. |
max | number | 5 | Maximum rating. |
name | string | - | The name attribute of the radio |
onChange | func | - | Callback fired when the value changes. Signature: function(event: React.SyntheticEvent, value: number | null) => void
|
onChangeActive | func | - | Callback function that is fired when the hover state changes. Signature: function(event: React.SyntheticEvent, value: number) => void
|
precision | number | 1 | The minimum increment value change allowed. |
readOnly | bool | false | Removes all hover effects and pointer events. |
size | 'small' | 'medium' | 'large' | string | 'medium' | The size of the component. |
sx | Array<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. |
value | number | - | The rating value. |
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.
These class names are useful for styling with CSS. They are applied to the component's slots when specific states are triggered.
Class name | Rule name | Description |
---|---|---|
.Mui-disabled | State class applied to the root element if disabled={true} . | |
.Mui-focusVisible | State class applied to the root element if keyboard focused. | |
.Mui-readOnly | Styles applied to the root element if readOnly={true} . | |
.MuiRating-decimal | decimal | Styles applied to the icon wrapping elements when decimals are necessary. |
.MuiRating-icon | icon | Styles applied to the icon wrapping elements. |
.MuiRating-iconActive | iconActive | Styles applied to the icon wrapping elements when active. |
.MuiRating-iconEmpty | iconEmpty | Styles applied to the icon wrapping elements when empty. |
.MuiRating-iconFilled | iconFilled | Styles applied to the icon wrapping elements when filled. |
.MuiRating-iconFocus | iconFocus | Styles applied to the icon wrapping elements when focus. |
.MuiRating-iconHover | iconHover | Styles applied to the icon wrapping elements when hover. |
.MuiRating-label | label | Styles applied to the label elements. |
.MuiRating-labelEmptyValueActive | labelEmptyValueActive | Styles applied to the label of the "no value" input when it is active. |
.MuiRating-root | root | Styles applied to the root element. |
.MuiRating-sizeLarge | sizeLarge | Styles applied to the root element if size="large" . |
.MuiRating-sizeMedium | sizeMedium | Styles applied to the root element if size="medium" . |
.MuiRating-sizeSmall | sizeSmall | Styles applied to the root element if size="small" . |
.MuiRating-visuallyHidden | visuallyHidden | Visually hide an element. |
You can override the style of the component using one of these customization options:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.