Build faster with Premium Chakra UI Components 💎

Learn more
Skip to Content
DocsPlaygroundGuidesBlog
Sponsor

Rating

Used to show reviews and ratings in a visual format.

StorybookRecipeArk

Usage

import { RatingGroup } from "@chakra-ui/react"
<RatingGroup.Root>
  <RatingGroup.HiddenInput />
  <RatingGroup.Control>
    <RatingGroup.Item>
      <RatingGroup.ItemIndicator />
    </RatingGroup.Item>
  </RatingGroup.Control>
</RatingGroup.Root>

Examples

Sizes

Use the size prop to change the size of the rating component.

Controlled

Use the value and onValueChange prop to control the rating value.

Store

An alternative way to control the rating is to use the RootProvider component and the useRatingGroup store hook.

This way you can access the rating state and methods from outside the component.

ReadOnly

Use the readOnly prop to make the rating component read-only.

Hook Form

Here's an example of how to use rating with react-hook-form.

Custom Icon

Use the icon prop to pass a custom icon to the rating component. This will override the default star icon.

Half Star

Use the allowHalf prop to allow half-star ratings.

Emoji

Compose the rating component with emojis.

😡😠😐😊😍

Colors

Use the colorPalette prop to change the color of the rating

gray

red

green

blue

teal

pink

purple

cyan

orange

yellow

Testimonial

Use the rating component to show testimonials.

Sage is a great software engineer. He is very professional and knowledgeable.

MJ

Matthew Jones

CTO, Company

Closed Component

Here's how to setup the Rating for a closed component composition.

import { RatingGroup } from "@chakra-ui/react"
import * as React from "react"

export interface RatingProps extends RatingGroup.RootProps {
  icon?: React.ReactElement
  count?: number
  label?: React.ReactNode
}

export const Rating = React.forwardRef<HTMLDivElement, RatingProps>(
  function Rating(props, ref) {
    const { icon, count = 5, label, ...rest } = props
    return (
      <RatingGroup.Root ref={ref} count={count} {...rest}>
        {label && <RatingGroup.Label>{label}</RatingGroup.Label>}
        <RatingGroup.HiddenInput />
        <RatingGroup.Control>
          {Array.from({ length: count }).map((_, index) => (
            <RatingGroup.Item key={index} index={index + 1}>
              <RatingGroup.ItemIndicator icon={icon} />
            </RatingGroup.Item>
          ))}
        </RatingGroup.Control>
      </RatingGroup.Root>
    )
  },
)

Usage

<Rating defaultValue={3} size="sm" />

Props

Root

PropDefaultType
count '5'
number

The total number of ratings.

colorPalette 'gray'
'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink' | 'accent'

The color palette of the component

size 'md'
'xs' | 'sm' | 'md' | 'lg'

The size of the component

allowHalf
boolean

Whether to allow half stars.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
autoFocus
boolean

Whether to autofocus the rating.

defaultValue
number

The initial value of the rating group when it is first rendered. Use when you do not need to control the state of the rating group.

disabled
boolean

Whether the rating is disabled.

form
string

The associate form of the underlying input element.

id
string

The unique identifier of the machine.

ids
Partial<{ root: string label: string hiddenInput: string control: string item(id: string): string }>

The ids of the elements in the rating. Useful for composition.

name
string

The name attribute of the rating element (used in forms).

onHoverChange
(details: HoverChangeDetails) => void

Function to be called when the rating value is hovered.

onValueChange
(details: ValueChangeDetails) => void

Function to be called when the rating value changes.

readOnly
boolean

Whether the rating is readonly.

required
boolean

Whether the rating is required.

translations
IntlTranslations

Specifies the localized strings that identifies the accessibility elements and their states

value
number

The current rating value.

as
React.ElementType

The underlying element to render.

unstyled
boolean

Whether to remove the component's style.

Item

PropDefaultType
index *
number

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.

Previous

Radio

Next

Segmented Control