Rating
Used to show reviews and ratings in a visual format.
Usage
import { RatingGroup } from "@chakra-ui/react"<RatingGroup.Root>
<RatingGroup.Label />
<RatingGroup.HiddenInput />
<RatingGroup.Control>
<RatingGroup.Item>
<RatingGroup.ItemIndicator />
</RatingGroup.Item>
</RatingGroup.Control>
</RatingGroup.Root>Shortcuts
The Rating component also provides a set of shortcuts for common use cases.
RatingControl
This component renders the number of rating items specified in the count prop.
This works:
<RatingGroup.Control>
{Array.from({ length: 5 }).map((_, index) => (
<RatingGroup.Item key={index} index={index + 1}>
<RatingGroup.ItemIndicator />
</RatingGroup.Item>
))}
</RatingGroup.Control>This might be more concise, if you don't need to customize the rating icons:
<RatingGroup.Control />Examples
Basic
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.
Label
Render the RatingGroup.Label component to provide a human-readable label for
the rating component.
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.

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>
)
},
)
Here's how to use the it
<Rating defaultValue={3} size="sm" />Props
Root
| Prop | Default | Type |
|---|---|---|
count | 5 | numberThe total number of ratings. |
colorPalette | gray | 'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'The color palette of the component |
size | md | 'xs' | 'sm' | 'md' | 'lg'The size of the component |
as | React.ElementTypeThe underlying element to render. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. | |
unstyled | booleanWhether to remove the component's style. | |
allowHalf | booleanWhether to allow half stars. | |
autoFocus | booleanWhether to autofocus the rating. | |
defaultValue | numberThe initial value of the rating when rendered. Use when you don't need to control the value of the rating. | |
disabled | booleanWhether the rating is disabled. | |
form | stringThe associate form of the underlying input element. | |
id | stringThe 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 | stringThe name attribute of the rating element (used in forms). | |
onHoverChange | (details: HoverChangeDetails) => voidFunction to be called when the rating value is hovered. | |
onValueChange | (details: ValueChangeDetails) => voidFunction to be called when the rating value changes. | |
readOnly | booleanWhether the rating is readonly. | |
required | booleanWhether the rating is required. | |
translations | IntlTranslationsSpecifies the localized strings that identifies the accessibility elements and their states | |
value | numberThe controlled value of the rating |
Item
| Prop | Default | Type |
|---|---|---|
index * | number | |
as | React.ElementTypeThe underlying element to render. | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. For more details, read our Composition guide. |