Rating renders a read-style star row with optional partial fill, custom icon, and trailing text.
Setup
<script lang="ts">
import { Rating } from '.';
</script> Default rating
Defaults to rating={4} of total={5} at size={24}.
<Rating /> With text snippet
4.5 out of 5
<script lang="ts">
import { Rating } from '.';
</script>
<Rating rating={4.5}>
{#snippet text()}
<p class="ms-2 text-sm font-medium text-gray-500">4.5 out of 5</p>
{/snippet}
</Rating> Count mode
count shows a single filled star plus the numeric value; put review copy in children.
3.2
(12 reviews)
<script lang="ts">
import { Rating } from '.';
</script>
<Rating count rating={3.2}>
<p class="ms-2 text-sm">(12 reviews)</p>
</Rating> Custom size / total
<Rating size={18} rating={3} />
<Rating size={32} total={10} rating={7.5} /> Partial fills
Fractional rating values fill the next star by percentage.
<Rating rating={3.25} />
<Rating rating={3.5} />
<Rating rating={3.75} /> Custom icon
Pass any component that implements RatingIconProps (fillPercent, size, groupId, …). Default icon is Star.
<script lang="ts">
import { Rating } from '.';
import CustomStar from './CustomStar.svelte';
</script>
<Rating rating={4} icon={CustomStar} /> Props
| Prop | Type | Default | Description |
|---|---|---|---|
rating | number | 4 | Filled value (supports fractions) |
total | number | 5 | Number of icons |
size | number | 24 | Icon size in px |
count | boolean | false | Compact single-star + value layout |
text | Snippet | — | Trailing text when not in count mode |
children | Snippet | — | Extra content (used with count) |
icon | Component<RatingIconProps> | Star | Custom star icon component |
class / classes | theme slots | — | base / value overrides |
...rest | HTMLAttributes<HTMLDivElement> | — | Root attributes |
RatingIconProps (custom icons)
| Prop | Type | Description |
|---|---|---|
fillPercent | number | 0–100 fill |
fillColor / strokeColor | string | Colors |
size | number | Pixel size |
ariaLabel | string | Accessible label |
iconIndex / groupId | number / string | Gradient id helpers |
role | string | SVG role |