VOOZH about

URL: https://www.geeksforgeeks.org/javascript/star-rating-using-html-css-and-javascript/

⇱ Star Rating using HTML CSS and JavaScript - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Star Rating using HTML CSS and JavaScript

Last Updated : 23 Jul, 2025

Star rating is a way to give a rating to the content to show its quality or performance in different fields. This article will demonstrate how to create a star rating project using JavaScript.

Project Preview:

👁 Screenshot-from-2023-07-26-11-16-31

Prerequisites

Step-by-Step Guide to Building a Star Rating System

  • Create the basic structure using HTML entities, divs, and spans along with the corresponding class names. Using CSS styling properties, style the components with CSS properties like display, color, font size, margin, padding, and border for respective classes.
  • In JavaScript access the html element using a document.getElementByClass name to get the list of span elements and getElementById.
  • Use onclickattribute as an event listener to call the function according to the no. of star clicked.
  • Remove already applied CSS by calling the remove method.
  • Update the color of the stars and the output corresponding to the author's action.

Example: In this example, we will create the star rating with the above approach.

Output:

👁 starrrrrr

Comment