Create a Product Review and Rating System Using HTML CSS and JavaScript Last Updated : 25 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Creating a product review and rating system using HTML, CSS, and JavaScript involves several steps. In this article, we will create a Product Review and Rating System using HTML, CSS, and JavaScript.Approach:Create the HTML structure for your product review and rating system. You'll need sections for product information, user reviews, and a form for submitting new reviews.Style your product review and rating system using the CSS. Define the styles for product information, reviews, review forms, and rating stars.Use JavaScript to handle the interactivity. Implement functions for displaying average ratings, updating user reviews, and handling the form submission.Example: Below is the implementation. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="style.css"> <title>The Product Review and Rating</title> </head> <body> <div class="container"> <h1>GeeksforGeeks Java Course</h1> <div class="rating"> <span id="rating">0</span>/5 </div> <div class="stars" id="stars"> <span class="star" data-value="1">★</span> <span class="star" data-value="2">★</span> <span class="star" data-value="3">★</span> <span class="star" data-value="4">★</span> <span class="star" data-value="5">★</span> </div> <p>Share your review:</p> <textarea id="review" placeholder="Write your review here"> </textarea> <button id="submit">Submit</button> <div class="reviews" id="reviews"> </div> </div> <script src="script.js"></script> </body> </html> CSS body { font-family: Arial, sans-serif; background-color: #0000FF; margin: 0; display: flex; justify-content: center; align-items: center; min-height: 100vh; } .container { background-color: white; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); text-align: center; width: 400px; } h1 { font-size: 24px; margin: 0; } .rating { font-size: 20px; margin: 10px 0; } .stars { font-size: 30px; margin: 10px 0; } .star { cursor: pointer; margin: 0 5px; } .one { color: rgb(255, 0, 0); } .two { color: rgb(255, 106, 0); } .three { color: rgb(251, 255, 120); } .four { color: rgb(255, 255, 0); } .five { color: rgb(24, 159, 14); } textarea { width: 90%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; } button { background-color: #007BFF; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #0056b3; } .reviews { margin-top: 20px; text-align: left; } .review { border: 1px solid #ccc; border-radius: 4px; padding: 10px; margin: 10px 0; } .review p { margin: 0; } JavaScript const stars = document.querySelectorAll(".star"); const rating = document.getElementById("rating"); const reviewText = document.getElementById("review"); const submitBtn = document.getElementById("submit"); const reviewsContainer = document.getElementById("reviews"); stars.forEach((star) => { star.addEventListener("click", () => { const value = parseInt(star.getAttribute("data-value")); rating.innerText = value; // Remove all existing classes from stars stars.forEach((s) => s.classList.remove("one", "two", "three", "four", "five")); // Add the appropriate class to // each star based on the selected star's value stars.forEach((s, index) => { if (index < value) { s.classList.add(getStarColorClass(value)); } }); // Remove "selected" class from all stars stars.forEach((s) => s.classList.remove("selected")); // Add "selected" class to the clicked star star.classList.add("selected"); }); }); submitBtn.addEventListener("click", () => { const review = reviewText.value; const userRating = parseInt(rating.innerText); if (!userRating || !review) { alert( "Please select a rating and provide a review before submitting." ); return; } if (userRating > 0) { const reviewElement = document.createElement("div"); reviewElement.classList.add("review"); reviewElement.innerHTML = `<p><strong>Rating: ${userRating}/5</strong></p><p>${review}</p>`; reviewsContainer.appendChild(reviewElement); // Reset styles after submitting reviewText.value = ""; rating.innerText = "0"; stars.forEach((s) => s.classList.remove("one", "two", "three", "four", "five", "selected")); } }); function getStarColorClass(value) { switch (value) { case 1: return "one"; case 2: return "two"; case 3: return "three"; case 4: return "four"; case 5: return "five"; default: return ""; } } Output: Create a Product Review and Rating System Using HTML CSS and JavaScript Comment More infoAdvertise with us Next Article Create a Quiz App with Timer using HTML CSS and JavaScript S subramanyasmgm Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League JavaScript-Projects Geeks Premier League 2023 +1 More Similar Reads How to create a dynamic report card using HTML, CSS and JavaScript ? We have to build a website where you can upload your student data like their name and marks in different subjects. And after uploading it will insert the student data in the table as well as, it will show the total marks, average, and pass/fail status. The implementation is done by using HTML and Ja 2 min read Create a Single Page Application using HTML CSS & JavaScript In this article, we are going to design and build a cool and user-friendly single-page application (SPA) using just HTML, CSS, and JavaScript. A single-page application contains multiple pages that can be navigated or visited without loading the page every time. This makes things faster and more int 4 min read Create an Online Art Auction using HTML, CSS and JavaScript In this article, we'll guide you through the process of creating an online art auction website using HTML, CSS, and JavaScript. Art auctions are exciting events where collectors and enthusiasts bid on prized artworks. It will provide a foundation for displaying art listings and creating an appealing 3 min read Create a Quiz App with Timer using HTML CSS and JavaScript Creating a quiz app is an excellent way to learn the fundamentals of web development. In this tutorial, we will build a Quiz App that features a timer, allowing users to take a timed quiz with multiple-choice questions. The app will use HTML for the structure, CSS for styling, and JavaScript for fun 9 min read Star Rating using HTML CSS and JavaScript 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:PrerequisitesHTMLCSSJavaScriptStep-by-Step Guide to Building a Star Rating SystemCreate the 3 min read Create a User Polls Project using HTML CSS & JavaScript Creating a user polls project has various valuable purposes, including gathering feedback, engaging users, personalizing content, fostering community, conducting research, A/B testing, and improving the user experience. Clear objectives are crucial, and in this example, we focus on collecting data o 3 min read Like