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. |
component | elementType | - | The component used for the root node. Either a string to use a HTML element or a component. |
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 || '0'} 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. |
slotProps | { decimal?: func | object, icon?: func | object, label?: func | object, root?: func | object } | {} | The props used for each slot inside. |
slots | { decimal?: elementType, icon?: elementType, label?: elementType, root?: elementType } | {} | The components used for each slot inside. |
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.
Slot name | Class name | Default component | Description |
---|---|---|---|
root | .MuiRating-root | 'span' | The component used for the root slot. |
label | .MuiRating-label | 'label' | The component used for the label slot. |
icon | .MuiRating-icon | 'span' | The component used for the icon slot. |
decimal | .MuiRating-decimal | 'span' | The component used fo r the decimal slot. |
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-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-labelEmptyValueActive | labelEmptyValueActive | Styles applied to the label of the "no value" input when it is active. |
.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.
Source code
If you did not find the information in this page, consider having a look at the implementation of the component for more detail.