A simple yet powerful JQuery star rating plugin for Bootstrap which supports advanced features like fractional star fill and RTL input support. Developed with a focus on utlizing pure CSS-3 styling to render the control. The plugin uses Bootstrap markup and styling by default, but it can be overridden with any other CSS markup. View a complete demo.
Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)
Convert any HTML input to a star rating control.
Accessibility enabled and allows rating navigation and modification via the keyboard.
Easy Configuration: The plugin automatically converts an input to a star rating control if you set its class = rating
. All options to the input can be passed as HTML5 data
attributes.
The plugin supports fractional star ratings. So one can have any fractional stars highlighted and managed. This is totally configurable and one of a significant differentiator as compared to most other rating plugins.
Ability to size the rating control to any size including the stars, caption, and clear button. Five prebuilt size templates are available xl
, lg
, md
, sm
, and xs
. However one can have their own size configured through a simple CSS manipulation.
Use any of your favorite font icon frameworks to render your star symbols (for example you can easily use the icons from the FontAwesome library).
The plugin supports themes for advanced styling.
The plugin includes translation and locale support for multi languages.
You can use the HTML 5 number input for polyfill and the plugin will automatically use the number attributes like min
, max
, and step
. However, number inputs have a problem with decimal values on the Chrome Browser. Read the Browser Support section below.
Involves pure CSS3 styling of the stars. Say goodbye to image sprites or playing with image backgrounds. Offers clean scalable vector icons for consistent display across devices.
Specifically uses Bootstrap 3.x styles & glyphs. Can be combined to work better for Bootstrap styled projects (or input group addons).
Ability to clear values and options for the stars. Control where the clear button element can be shown.
Reset star rating to the initial value when the form is reset.
Ability to control and display caption of the selected stars. Each rated star can have its own caption. Control where the caption element can be shown.
Support for RIGHT TO LEFT (RTL) input. Automatically changes star styling for RTL.
Triggers JQuery events for advanced development. Events currently available are rating:change
, rating:clear
, and rating:reset
.
Disabled and readonly input star rating support.
Change stars and caption on mouse hover (new feature since v3.0.0).
Change stars and caption on slide and drag for mobile/touch devices (new feature since v3.1.0).
BC Breaking Changes: The symbol
and glyphicon
properties have been be removed. The functionality is replaced with the theme
property (and can also be complemented or implemented separately using the containerClass
property).
New property theme
will assign a CSS class with the rating-<theme-name>
to the rating container. Themes included with the plugin:
krajee-svg
(for displaying SVG icons)
krajee-gly
(for displaying bootstrap 3.x glyphicons)
krajee-uni
(for displaying UNICODE symbols as stars)
krajee-fa
(for displaying FONT AWESOME 4.x icons)
krajee-fas
(for displaying FONT AWESOME 5.x icons and above)
Add ability to override and add one's own themes.
Stars now have a better padding and spacing that can be configured via CSS and themes.
New property filledStar
that will allow one to set the markup for filledStar
. This defaults to <i class="glyphicon glyphicon-star"></i>
. Note that unlike earlier releases no symbol
is needed anymore. One can setup a HTML markup here and can thus achieve richer/complex markup for displaying their stars.
New property emptyStar
that will allow one to set the markup for emptyStar
. This defaults to <i class="glyphicon glyphicon-star-empty"></i>
. Note that unlike earlier releases no symbol
is needed anymore. One can setup a HTML markup here and can thus achieve richer/complex markup for displaying their stars.
Exclusive support for SVG (and a prebuilt krajee-svg
theme that contains two different ready to use SVG icons).
Ability to easily set the widget as a "display only" rating via displayOnly
property.
New property animate
to control animation of highlighted stars on hover or click.
When using the rtl
mode, you must ensure that the icon markup you set in filledStar
is symmetrical horizontally. This is because the plugin default CSS styling uses a horizontal mirror flipped version of the filledStar
markup.
The rtl
input ratings are by default floated right. You may need to add a <div class="clearfix></div>
for bootstrap styling after RTL ratings to ensure that floats are cleared for subsequent content displayed.
If you are already using a HTML markup on your page which has the content RTL oriented, then you must be careful in setting the rtl
property. For example, if you have an <html dir="rtl">
at top of your page and wish to have a RTL oriented star rating, then you may take one of the following approaches to render a proper RTL rating
Option 1: Wrap the rating inside a LTR container e.g. <div dir="ltr">
.
Option 2: You can set the rtl
setting for the plugin to false
.
Latest JQuery
Most modern browsers supporting CSS3, HTML5 inputs, & JQuery. For Internet Explorer, one must use IE versions 9 and above to render the rating.
Bootstrap 3.x is optional and used by default, but can be overridden to use any CSS.
The bootstrap-star-rating plugin can be installed automatically or manually using one of these options:
Installation via bower package manager is as simple as running:
$ bower install bootstrap-star-rating
Installation via NPM is as simple as running:
$ npm install bootstrap-star-rating
[input class="rating"]
to a star rating control, i.e. if you
attach a css class rating
to the input. But, if you are initializing the plugin separately via javascript, then
DO NOT ATTACH the css class rating
to the input (as it will result in duplicate initializations and the javascript
code maybe skipped).
Step 1: Load the following assets in your header.
<link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-star-rating@4.0.7/css/star-rating.css" media="all" rel="stylesheet" type="text/css" /> <!-- optionally if you need to use a theme, then include the theme file as mentioned below --> <link href="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-star-rating@4.0.7/themes/krajee-svg/theme.css" media="all" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-star-rating@4.0.7/js/star-rating.js" type="text/javascript"></script> <!-- optionally if you need to use a theme, then include the theme file as mentioned below --> <script src="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-star-rating@4.0.7/themes/krajee-svg/theme.js"></script> <!-- optionally if you need translation for your language then include locale file as mentioned below (replace LANG.js with your locale specific file) --> <script src="https://cdn.jsdelivr.net/gh/kartik-v/bootstrap-star-rating@4.0.7/js/locales/LANG.js"></script>
If you noticed, you need to load the jquery.min.js
and bootstrap.min.css
in addition to the star-rating.min.css
and star-rating.min.js
. The theme files and translation files are optional addons.
Step 2a: Initialize the plugin on your page. For example,
// initialize with defaults $("#input-id").rating(); // with plugin options $("#input-id").rating({min:1, max:10, step:2, size:'lg'});
The #input-id
is the identifier for the input on your page, which is hidden automatically by the plugin.
Step 2b: Alternatively, you can directly set the plugin options to any input, through HTML 5 data attributes to your input field.
<input id="input-id" name="input-name" type="number" class="rating" min=1 max=10 step=2 data-size="lg" data-rtl="true">
/star-rating_locale_<lang>.js
after the core star-rating.min.js
file, where <lang>
is the language code (e.g. de
, fr
etc.). If locale file does not exist, you can submit a
translation for the new language via a new
pull request to add to this folder. Check the sample locale
file to copy and create a translation configuration for your own language.
The plugin has been implemented as extensions in the following frameworks
Sl. | Framework | Extension Source | Developed By | Extension Demo |
---|---|---|---|---|
1. | Yii Framework 2.0 | Yii2 Widgets | Krajee | Yii2 Star Rating |
Do you know any other framework extension using this plugin which is not listed here? Tell us so that we can consider its inclusion in this list.
bootstrap-star-rating is released under the BSD 3-Clause License. See the bundled LICENSE.md
for details.
Comments & Discussion
Note
You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.
The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.