Skip to main content
Ratings provide insight into others’ opinions and experiences with a product. Users can also rate products they’ve purchased.

Import

import Rating from '@mui/material/Rating';

Basic Usage

import * as React from 'react';
import Box from '@mui/material/Box';
import Rating from '@mui/material/Rating';
import Typography from '@mui/material/Typography';

export default function BasicRating() {
  const [value, setValue] = React.useState<number | null>(2);

  return (
    <Box sx={{ '& > legend': { mt: 2 } }}>
      <Typography component="legend">Controlled</Typography>
      <Rating
        name="simple-controlled"
        value={value}
        onChange={(event, newValue) => {
          setValue(newValue);
        }}
      />
      <Typography component="legend">Read only</Typography>
      <Rating name="read-only" value={value} readOnly />
      <Typography component="legend">Disabled</Typography>
      <Rating name="disabled" value={value} disabled />
    </Box>
  );
}

Props

value
number | null
The rating value.
defaultValue
number
default:"null"
The default value. Use when the component is not controlled.
max
number
default:"5"
Maximum rating.
precision
number
default:"1"
The minimum increment value change allowed.
size
'small' | 'medium' | 'large'
default:"'medium'"
The size of the component.
disabled
boolean
default:"false"
If true, the component is disabled.
readOnly
boolean
default:"false"
Removes all hover effects and pointer events.
highlightSelectedOnly
boolean
default:"false"
If true, only the selected icon will be highlighted.
icon
ReactNode
The icon to display. Defaults to <Star fontSize="inherit" />.
emptyIcon
ReactNode
The icon to display when empty. Defaults to <StarBorder fontSize="inherit" />.
emptyLabelText
ReactNode
default:"'Empty'"
The label read when the rating input is empty.
getLabelText
(value: number) => string
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. Default returns ${value || '0'} Star${value !== 1 ? 's' : ''}.
onChange
(event: React.SyntheticEvent, value: number | null) => void
Callback fired when the value changes.
onChangeActive
(event: React.SyntheticEvent, value: number) => void
Callback function that is fired when the hover state changes.
name
string
The name attribute of the radio input elements. This input name should be unique within the page.
sx
SxProps<Theme>
The system prop that allows defining system overrides as well as additional CSS styles.

API Reference

Build docs developers (and LLMs) love