Star Rating Widget
Collect star and smiley face ratings to measure user satisfaction
Overview
The star rating widget provides two rating styles for collecting user satisfaction data: classic star ratings (configurable from 1 to 10 stars) and emoji smiley faces (3 or 5 options). It supports half-star precision, keyboard navigation, and full internationalization.
Both star and smiley modes submit to the same unified rating API, making it easy to compare data across styles.
Quick Start
Add star ratings to your page with a single script tag:
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"></script>For smiley face ratings:
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-style="smiley"></script>The widget appears inline at the script tag location by default, showing a label and interactive rating controls.
Configuration Options
Customize the widget's appearance and behavior using data attributes:
Required Attributes
data-project-keystringrequiredYour unique project identifier from the SeggWat dashboard
Optional Attributes
data-stylestringdefault:"stars"Rating display style
stars— Classic star rating (default)smiley— Emoji smiley face rating
Example:
data-style="smiley"data-max-starsnumberdefault:"5"Number of stars to display (stars mode only). Accepts values from 1 to 10.
Example:
data-max-stars="10"data-facesnumberdefault:"3"Number of smiley faces (smiley mode only). Only 3 or 5 are supported.
3— Bad, Okay, Great5— Terrible, Bad, Okay, Good, Great
Example:
data-faces="5"data-labelstringdefault:"auto"Custom label text above the rating controls. You can also use data-question as an alias.
Defaults to "Rate your experience" for stars and "How was your experience?" for smiley mode. Translated automatically based on language.
data-allow-halfbooleandefault:"false"Enable half-star ratings for more precise feedback (stars mode only)
Example:
data-allow-half="true"data-show-countbooleandefault:"true"Display the numeric rating counter (e.g., "3/5") next to the stars
Set to false to hide the counter.
data-inlinebooleandefault:"false"Remove the top border styling for a more compact look
Useful when embedding the widget inside existing UI components.
data-colorstringdefault:"#f59e0b"Hex color code for filled stars and active smiley highlights
Example:
data-color="#ef4444"data-containerstringCSS selector for custom placement
By default, the widget inserts inline at the script tag location. Use this to place it in a specific container.
Example:
data-container="#rating-section"data-languagestringdefault:"auto-detect"Language code for the widget UI
Supported languages: en, de, sv
Falls back to English if unsupported. Auto-detects from browser if not specified.
data-versionstringTrack ratings against specific application versions (e.g., 1.2.3, v2.0.0-beta)
Helps correlate ratings with releases and identify version-specific satisfaction trends.
data-show-powered-bybooleandefault:"true"Show or hide the "Powered by SeggWat" branding
Set to false, 0, or no to hide the branding.
data-api-urlstringdefault:"auto-detect"Override the API endpoint (useful for self-hosted or staging environments)
Examples
Basic Star Rating
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"></script>10-Star Scale
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-max-stars="10"
data-show-count="true"></script>Half-Star Precision
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-allow-half="true"
data-color="#ef4444"></script>Smiley Faces (3 Options)
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-style="smiley"></script>Shows three emoji faces: Bad, Okay, Great.
Smiley Faces (5 Options)
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-style="smiley"
data-faces="5"></script>Shows five emoji faces: Terrible, Bad, Okay, Good, Great.
Custom Label
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-label="How would you rate this product?"></script>German Language
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-language="de"></script>Full Configuration
<script src="https://seggwat.com/static/widgets/v1/seggwat-rating.js"
data-project-key="your-project-key"
data-style="stars"
data-max-stars="5"
data-allow-half="true"
data-show-count="true"
data-color="#f59e0b"
data-label="Rate your experience"
data-language="en"
data-version="2.1.0"
data-show-powered-by="false"></script>JavaScript API
The widget exposes a global API for programmatic control:
Set User ID
Associate ratings with specific users:
if (window.SeggwatRating) {
SeggwatRating.setUser('user_12345');
}Only pass user IDs, not personally identifiable information (PII) like emails or names. This maintains GDPR compliance.
Validation:
- Max 255 characters
- Alphanumeric characters, hyphens, and underscores only
- Examples:
user_12345,cust-abc-123,USR_98765
Reset Widget
Reset the widget to its initial state:
SeggwatRating.reset();This clears the current rating and returns to the idle state, allowing the user to rate again.
Get Current Rating
Retrieve the current rating value:
const rating = SeggwatRating.getRating();
// Returns 0 if no rating has been submittedGet Current Style
Check which rating style is active:
const style = SeggwatRating.getStyle();
// Returns "stars" or "smiley"Access Container
Access the widget's DOM element:
const container = SeggwatRating.container;Keyboard Navigation
The widget supports full keyboard navigation:
| Key | Action |
|---|---|
Arrow Left / Arrow Down |
Decrease rating by one |
Arrow Right / Arrow Up |
Increase rating by one |
Enter / Space |
Submit the current rating |
Focus indicators are visible when navigating with the keyboard.
Use Cases
Product Pages
Let customers rate products with familiar star ratings. Compare satisfaction across your catalog.
SaaS Applications
Measure feature satisfaction with quick smiley ratings. Track happiness over time and across releases.
Support Articles
Go beyond helpful/not helpful with granular star ratings on support content.
E-commerce
Collect post-purchase ratings inline on order confirmation or product detail pages.
How It Works
- The script loads and auto-detects your site's base URL
- Core library loads automatically if not already present
- Widget inserts at script location (or specified container)
- User interacts with stars or smiley faces
- Rating submits to
POST /api/v1/ratings - Widget shows thank you message
- Widget enters submitted state (no duplicate submissions)
API Endpoint
The widget submits ratings to:
POST /api/v1/ratingsPayload:
{
"project_key": "uuid",
"rating": {
"type": "star",
"value": 4,
"max_stars": 5
},
"context": {
"path": "/current/page/path",
"version": "1.2.3",
"submitted_by": "user-id-123"
}
}rating.value— The selected rating (1 tomax_stars, supports 0.5 increments with half-stars)rating.max_stars— The configured maximum (1-10)context.version— Only included ifdata-versionis setcontext.submitted_by— Only included ifsetUser()was called
Response: 201 Created on success
Best Practices
Styling
The widget uses the SeggWat design system and adapts to light/dark mode automatically.
CSS Classes (for custom styling):
.seggwat-star-widget— Root container.seggwat-star-bordered— Applied when not inline.seggwat-star-inner— Inner wrapper.seggwat-star-label— Label text.seggwat-star-container— Stars/smiley container.seggwat-star-rating— Star rating group.seggwat-star— Individual star.seggwat-star.filled— Filled star.seggwat-star.half-filled— Half-filled star.seggwat-star-count— Rating counter.seggwat-star-hover-text— Hover description text.seggwat-smiley-faces— Smiley container.seggwat-smiley-face— Individual smiley button.seggwat-smiley-face.selected— Selected smiley.seggwat-smiley-face.dimmed— Dimmed after submission.seggwat-smiley-emoji— Emoji element.seggwat-smiley-label— Label below emoji
Example custom styling:
/* Change star size */
.seggwat-star {
font-size: 32px !important;
}
/* Custom label styling */
.seggwat-star-label {
font-size: 18px !important;
font-weight: 600 !important;
}Accessibility
The star rating widget is built with accessibility in mind:
- ARIA
radiogrouprole with individualradioroles for each option - Keyboard navigation with arrow keys and Enter/Space
- Focus indicators for keyboard users
- Hover text descriptions for each star level
- Disabled state after submission
- Sufficient color contrast
