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 Solution to the error “Visual Studio Code can’t be opened because Apple cannot check it for malicious software” #2 How to add Read More Read Less Button using JavaScript? #3 How to check if radio button is checked or not using JavaScript? #4 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to uninstall Cocoapods from the Mac OS?

Recently Posted

#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The Search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interface
You might also like these
How to force your website to load securely with an .htaccess file?MiscellaneousEverything you need to know about ANY, SOME and ALL Operators in PostgresPostgresHow to redirect or load a new document using JavaScript?JavaScriptHow to create a blurry text effect using CSS?CSSHow to create ‘share on LinkedIn’ link using just HTML?HTMLThe Difference Between Arrays and Objects in JavaScriptJavaScript