npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@devekkx/svelte-star-rating

v1.0.2

Published

Simple star rating component for Svelte

Readme

Svelte Star Rating

A simple, zero-dependency star rating component for Svelte 5. It supports partial fills, full keyboard and mouse interaction, a readonly display mode, and per-instance customization of colors, size, and stroke.

Installation

Install the package with your preferred package manager:

npm install @devekkx/svelte-star-rating
# or
pnpm add @devekkx/svelte-star-rating
# or
bun add @devekkx/svelte-star-rating

This package requires Svelte 5 as a peer dependency.

Quick start

Here is a basic interactive rating input:

<script lang="ts">
	import { StarRating } from '@devekkx/svelte-star-rating';

	let value = $state(4.4);

	const config = {
		readonly: false,
		maxVal: 5,
		minVal: 0,
		step: 0.1,
		numOfStars: 5,
		starConfig: {
			size: 26,
			filledColor: '#F98416',
			unfilledColor: '#5D5D5D'
		}
	};
</script>

<StarRating bind:value {config} /><p>Current rating: {value}</p>

And here is a read-only display, useful for showing an existing score:

<script lang="ts">
	import { StarRating } from '@devekkx/svelte-star-rating';

	let value = 3.7;

	const config = {
		readonly: true,
		minVal: 0,
		maxVal: 5,
		step: 0.1,
		numOfStars: 5,
		starConfig: {
			size: 20,
			filledColor: '#ffc107',
			unfilledColor: '#e0e0e0'
		}
	};
</script>

<StarRating {config} bind:value />

When readonly is true, the slider is disabled and the displayed rating cannot be changed by the user.

API

Component: StarRating

| Prop | Type | Required | Default | Description | | ------ | ------- | -------- | ------- | ----------------------------------------------------------- | | config | ConfigI | Yes | - | Controls behavior and appearance | | value | number | No | 4.54 | The current rating. Use bind:value to read and update it. |

Types

export interface StarConfigI {
	size: number; // Pixel size of each star SVG
	filledColor: string; // Fill color for filled stars
	unfilledColor: string; // Fill color for unfilled stars
	strokeColor?: string; // Outline color for each star. Defaults to filledColor when not set.
}

export interface ConfigI {
	name?: string; // Name attribute on the hidden range input. Defaults to "stars".
	readonly: boolean; // When true, the rating cannot be changed by the user.
	numOfStars: number; // How many stars to render.
	minVal: number; // Minimum selectable value.
	maxVal: number; // Maximum selectable value.
	step: number; // Granularity of the rating (e.g. 0.5 for half-stars, 1 for whole stars).
	starConfig: StarConfigI;
	styles?: {
		containerStyles?: string; // Inline CSS for the outer container element.
		starStyles?: string; // Inline CSS for the row of stars (useful for controlling gap).
	};
}

Stroke color

Each star has an outline that you can control with strokeColor inside starConfig. If you do not set it, the outline defaults to the same color as filledColor, making it visible on unfilled stars but seamless on filled ones.

A darker shade of your fill color is a common choice for the stroke:

starConfig: {
  size: 26,
  filledColor: '#F98416',
  unfilledColor: '#5D5D5D',
  strokeColor: '#C8690F'  // a darker orange outline
}

Or use a completely different color to create a distinct border effect:

starConfig: {
  size: 26,
  filledColor: '#ffd700',
  unfilledColor: '#e0e0e0',
  strokeColor: '#999999'
}

Partial fill

The value prop can be fractional. Stars at indices below Math.floor(value) are fully filled. The star at index Math.floor(value) is partially filled to show the fractional part. Stars beyond that are empty.

For example, with value = 3.7 and 5 stars:

  • Stars 1, 2, 3 are fully filled
  • Star 4 is 70% filled
  • Star 5 is empty

The step field controls how finely the user can adjust the rating. Use step: 1 for whole stars, step: 0.5 for half stars, or step: 0.1 for tenth-star precision.

Styling and customization

The component uses inline SVG fills, so star colors work without any external CSS.

To control layout and spacing, pass a styles object:

  • containerStyles is applied to the outer section wrapper. Use it to set margins, borders, padding, width, and alignment.
  • starStyles is applied to the row that holds the stars. Use it to control the gap between stars.

Example:

<script lang="ts">
	import { StarRating, type ConfigI } from '@devekkx/svelte-star-rating';

	let value = $state(4.4);

	const config: ConfigI = {
		readonly: false,
		maxVal: 5,
		minVal: 0,
		step: 0.1,
		numOfStars: 5,
		styles: {
			containerStyles:
				'border: 1px solid #ddd; padding: 8px; border-radius: 8px; width: max-content;',
			starStyles: 'gap: 0.2rem;'
		},
		starConfig: {
			size: 26,
			filledColor: '#F98416',
			unfilledColor: '#5D5D5D',
			strokeColor: '#C8690F'
		}
	};
</script>

<StarRating bind:value {config} />

More examples

Five stars, whole-number steps:

<script lang="ts">
	import { StarRating } from '@devekkx/svelte-star-rating';

	let value = $state(0);

	const config = {
		readonly: false,
		minVal: 0,
		maxVal: 5,
		step: 1,
		numOfStars: 5,
		starConfig: { size: 32, filledColor: 'gold', unfilledColor: '#ccc' }
	};
</script>

<StarRating bind:value {config} /><p>Your rating: {value}</p>

Ten stars, quarter-step precision:

<script lang="ts">
	import { StarRating } from '@devekkx/svelte-star-rating';

	let value = $state(7.5);

	const config = {
		readonly: false,
		minVal: 0,
		maxVal: 10,
		step: 0.25,
		numOfStars: 10,
		starConfig: { size: 18, filledColor: '#4f46e5', unfilledColor: '#e5e7eb' }
	};
</script>

<StarRating bind:value {config} />

Accessibility

When readonly is false, the underlying range input is keyboard-focusable and operable with arrow keys. Consider adding a visible label or aria-label attribute in your application to describe what the rating is for.

Notes

The component is exported as a named export:

import { StarRating } from '@devekkx/svelte-star-rating';
// types are also available
import type { ConfigI, StarConfigI } from '@devekkx/svelte-star-rating';

It requires Svelte 5. It renders correctly in server-side rendering environments since it is purely presentational. The range input interaction is client-only.

License

MIT License. Copyright 2025 Emmanuel Komla Kpendo.