Yogesh Chauhan's Blog

How to create a Star Ratings using CSS?

in CSS on August 3, 2019

In this short article, I will show you how to display star ratings for your products on your website. You can use the same ratings for your skills on portfolio as well. There are many ways to use the star ratings. I will show you the 5 star ratings example but you can use that for more than 5 star ratings as well, as long as you understand the basics.

Let's start with the basic HTML code.

In the HTML code, all you need is the icons and I am using icons from cloudflare.com. They provided stylesheet link to use any icons which are available in their link. Just go ahead and copy that link.

Now, I've simply added 5 different div elements, you can use span elements as well. The classes I am using aew fa and fa-star, which are from the link we just added. It automatically adds the stars using icons and our most part is done.

Let's take a quick look at the CSS.

In the HTML, you saw that I've added third class in first 3 div elements and that's what I am using here in CSS to style those 3 stars as selected by simply changing their colors.

This is very basic display of the star ratings and I haven't used any CSS style or selectors to make the stars clickable but I am going to do that in the next article. Still, you can use this in PHP as well as Java to get user ratings and set it as final ratings in database and then display it on the website. It's the easiest way to combine those tools.

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to show slider value in HTML5 range input using JavaScript?HTMLA quick introduction to API, REST API and PostmanMiscellaneousWhat is a “promise” in JavaScript?JavaScriptDebugging in WordPress Part 2: WP_DEBUG_LOG and WP_DEBUG_DISPLAYWordPressHow to import a CSS file using PHP code and not HTML code?PHPFor In Loop in Swift for BeginnersSwift