Home / Forms and Input / Star Rating and Review Form

Star Rating and Review Form in JavaScript, Free with Live Demo

Free star rating and review form in plain JavaScript. Half star ratings with radio buttons, hover preview, review text with a counter, photo previews and a live rating summary.

Open live demoDownload HTML fileView code on GitHub
Star Rating and Review Form JavaScript project: a review form with half star ratings, photos and a live rating summary

Runs on: Radio inputs and FileReader. Works in all modern browsers.

What is the Star Rating and Review Form?

A product review form with half star ratings, a name, a comment with a character counter and up to four photos.

Next to it is a rating summary with the average score and a bar for each star level. Posting a review updates the summary and adds it to the top of the list.

Good for

  • Product pages in online shops
  • Restaurant, hotel and service reviews
  • Course and app feedback
  • Internal quality surveys

What this project does

How it works

  1. Stars are radio buttonsTen hidden radio inputs, one for each half star, make the rating work with a keyboard and screen readers for free.
  2. Paint on hover and changeHovering previews a rating and the label changes to words like Great. Leaving restores the chosen value.
  3. Recalculate the summaryThe average, star counts and bar widths are worked out again from the list every time a review is added.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

<fieldset class="stars">
  <legend>Your rating</legend>
  <input type="radio" name="star" id="s1" value="0.5"><label for="s1">0.5 stars</label>
  <!-- ... up to 5 -->
</fieldset>

stars.addEventListener("change", (e) => paint(+e.target.value));
const avg = reviews.reduce((a, r) => a + r.stars, 0) / reviews.length;
bar.style.width = (count / reviews.length) * 100 + "%";

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

Why build stars from radio buttons?

Radio buttons already work with a keyboard and screen readers. The stars are just their labels styled.

How do I save reviews?

Send the form data to your server with fetch. The demo keeps reviews in memory only.

Should I show the average with decimals?

Show one decimal, like 4.3, and round the stars to the nearest half.

More Forms and Input projects