Sections
Get Started
Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Fancy Button
- Field
- Filter
- Form
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Number Field
- Pagination
- Pin Input
- Popover
- Progress
- Radio Group
- Radio Stack
- Range Calendar
- Rating
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Stepper
- Swatch
- Swatch Group
- Switch
- Table
- Tabs
- Tags Input
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Typography
Forms
This is a Frontic UI custom component.
<script setup lang="ts">
import { Rating } from '@/components/ui/rating'
</script>
<template>
<div class="flex flex-wrap items-center gap-4">
<Rating :rating="4" />
<Rating :rating="3" />
<Rating :rating="5" />
</div>
</template>Installation
pnpm dlx @frontic/ui add rating
Usage
<script setup lang="ts">
import { Rating } from '@/components/ui/rating'
</script>
<template>
<Rating :rating="4" />
</template>Props
| Prop | Type | Default | Description |
|---|---|---|---|
rating | number | (required) | The rating value to display |
max | number | 5 | Maximum number of stars |
color | 'default' | 'primary' | 'inverted' | 'default' | Color variant for the stars |
size | 'default' | 'sm' | 'lg' | 'default' | Size of the stars |
showValue | boolean | false | Whether to show the rating value and count |
count | number | - | Number of ratings (shown when showValue is true) |
Accessibility
The Rating component includes built-in accessibility features:
role="img"on the container elementaria-labelwith readable rating description (e.g., "4 out of 5 stars")aria-hidden="true"on individual star icons to prevent screen reader repetition
Colors
Available color variants for the rating stars.
Default
Primary
Inverted
<script setup lang="ts">
import { Rating } from '@/components/ui/rating'
</script>
<template>
<div class="flex flex-col gap-4">
<div class="flex items-center gap-4">
<span class="w-20 text-sm text-muted-foreground">Default</span>
<Rating :rating="4" color="default" />
</div>
<div class="flex items-center gap-4">
<span class="w-20 text-sm text-muted-foreground">Primary</span>
<Rating :rating="4" color="primary" />
</div>
<div class="flex items-center gap-4">
<span class="w-20 text-sm text-muted-foreground">Inverted</span>
<Rating :rating="4" color="inverted" />
</div>
</div>
</template>Sizes
Rating stars come in three sizes.
Small
Default
Large
<script setup lang="ts">
import { Rating } from '@/components/ui/rating'
</script>
<template>
<div class="flex flex-col gap-4">
<div class="flex items-center gap-4">
<span class="w-16 text-sm text-muted-foreground">Small</span>
<Rating :rating="4" size="sm" />
</div>
<div class="flex items-center gap-4">
<span class="w-16 text-sm text-muted-foreground">Default</span>
<Rating :rating="4" size="default" />
</div>
<div class="flex items-center gap-4">
<span class="w-16 text-sm text-muted-foreground">Large</span>
<Rating :rating="4" size="lg" />
</div>
</div>
</template>Examples
With Meta Information
Display the rating value and total number of ratings.
4.5/5
3.8/5(128)
4.9/5(2547)
<script setup lang="ts">
import { Rating } from '@/components/ui/rating'
</script>
<template>
<div class="flex flex-col gap-4">
<Rating :rating="4.5" show-value />
<Rating :rating="3.8" :count="128" show-value />
<Rating :rating="4.9" :count="2547" show-value size="sm" />
</div>
</template>Custom Max Stars
Use a different number of maximum stars.
<script setup lang="ts">
import { Rating } from '@/components/ui/rating'
</script>
<template>
<div class="flex flex-col gap-4">
<Rating :rating="7" :max="10" size="sm" />
<Rating :rating="3" :max="4" />
</div>
</template>Custom Icon
Use the RatingIcon slot to customize the icon.
<script setup lang="ts">
import { Heart } from 'lucide-vue-next'
import { Rating, RatingIcon, ratingVariants } from '@/components/ui/rating'
import { cn } from '@/lib/utils'
</script>
<template>
<div class="flex flex-col gap-4">
<div class="flex items-center gap-0.5">
<RatingIcon
v-for="i in 5"
:key="i"
:class="cn(ratingVariants({ size: 'default' }), i <= 4 ? 'fill-red-500 stroke-red-500' : 'fill-gray-200 stroke-gray-200')"
>
<Heart class="h-full w-full" />
</RatingIcon>
</div>
</div>
</template>