Free web tool

CSS Star Rating Generator

Make a CSS star rating for your website. Show a score with partial stars, or build a clickable star rating input for a form. Pick the size and colors, then copy the HTML and CSS. Free, with no account.

Updated November 2026

Preview

How to use the CSS star rating generator

First choose the type. "Show a rating" draws stars for a score you already have, like 4.7 out of 5. "Clickable rating input" draws stars that a visitor can click to choose a rating in a form. Then set the size and the two colors. The preview changes as you type.

When it looks right, press "Copy all". Paste the code into an HTML block on your page. If your site keeps CSS in a separate file, use "Copy CSS only" for the style file and "Copy HTML only" for the page.

How the star rating CSS works

The display stars are five star characters in a row. A gradient colors them from left to right. It is gold up to your rating and gray after it. The text itself is made see-through, so only the gradient shows through the star shapes.

The rating lives in a CSS variable called --rating. Change the number in the HTML, and the stars change with it. You can reuse the same CSS for many ratings on one page. Each one just needs its own --rating value.

The clickable version uses five radio buttons in reverse order. When you hover or pick a star, CSS colors that star and every star before it. Because they are real radio buttons, the chosen value is sent with the form like any other field.

Star rating HTML for screen readers

Star shapes mean nothing to a screen reader on their own. The display code adds a label such as "Rated 4.7 out of 5", and hides the star characters from screen readers. The clickable version has a hidden "Your rating" heading, and each star has a matching label. Keyboard users can use the arrow keys to move between stars.

Where to use a CSS star rating

  • Product and service cards. Show the average score next to each item.
  • Feedback forms. Use the clickable stars to ask how a visit went.
  • Testimonials. Put the stars above a quote from a customer.
  • Comparison tables. Show scores side by side in one column.

Only show ratings that are real. If you show a business rating, it should match the source, such as your Google listing. A made-up score can break consumer rules, and visitors lose trust when the numbers do not match.

Want your real Google rating instead?

The code above shows any number you type. It does not know your Google score, and it will not update when new reviews come in. To show your live Google rating and the reviews behind it, use a Google reviews badge or the rating breakdown widget. Need a quick image instead? The badge generator also makes a free 5 star review image.

CSS star rating examples

Here are a few ways people use the code. Each one starts from the same CSS, with a different rating number in the HTML.

  • A store rating in a header. Set the rating to your real score and turn on Show the number, so the stars and the score sit side by side.
  • A row of product cards. Copy the CSS once, then give each card its own HTML with its own --rating value.
  • A feedback form. Use the clickable rating input inside your form. The chosen star is sent as a field called rating.
  • A comparison table. Turn off Show the number and use a small size, so the stars fit in a narrow column.

Star rating with half stars

Half stars need no extra images. Type 4.5 into the rating box, and the gold fill stops halfway across the fifth star.

The rating box goes from 0 to 5 in steps of 0.1. So 3.5, 4.2 and 4.8 all work. The fill is a straight line, so a value like 4.2 shows a thin slice of the last star.

To show a half star exactly, keep the rating at a value ending in .5. You can also edit the --rating value in the HTML by hand later.

How to change star size and spacing

Set the size in pixels in the tool, anywhere from 12 to 80. The number next to the stars scales with them.

Spacing is not a setting in the tool, but it is easy to change in the code. In the display version, edit letter-spacing in the stars rule. It starts at 2px.

In the clickable version, change gap in the .star-input rule. It starts at 4px. The gap between the stars and the number is the gap in .star-rating.

Keep display spacing small. Large letter spacing adds room after the last star too, so the fill can look slightly off.

Star rating in React, WordPress and Shopify

The code is plain HTML and CSS, so it works anywhere you can paste custom code.

  • WordPress. Add a Custom HTML block and paste the full code with Copy all.
  • Shopify. Use a Custom Liquid section or a custom HTML block, depending on your theme. Paste the full code there.
  • React. Put the CSS in your stylesheet. In the HTML, change class to className and for to htmlFor. The inline style becomes an object.
  • Other builders. Wix, Squarespace and Webflow all have an embed or code block for this.

Common star rating CSS problems

  • The stars look different from the preview. The code uses the star character from the font. Some fonts draw it slightly differently, so set the font if needed.
  • The stars show as solid boxes or one color. Your theme may override the background or text color. Add the CSS after your theme styles, or make the selector more specific.
  • Two forms interfere with each other. Each star input uses one field name for its ids and radio group. Set a different field name in the generator for each rating on the same page.
  • Hover colors the wrong stars. The inputs are written from 5 down to 1 on purpose. Keep that order when you edit the HTML.
  • The code does nothing. You may have pasted it into a text block, which shows the code as words. Use an HTML or code block.

Sources and further reading

Frequently asked questions

How do I show a half star in CSS?

Set the rating to a number ending in .5, such as 4.5. The gradient stops halfway through the last star.

Can I use two clickable star inputs on one page?

Yes, but change the ids and the name in the second copy. Otherwise a click in one form can select a star in the other.

How do I make a star rating in CSS?

Write five star characters, then color them with a gradient that stops at your rating. The tool above writes this code for you. Pick a rating, size and colors, then copy the HTML and CSS.

Can CSS show partial stars like 4.5 or 4.7?

Yes. The display code uses a CSS variable called --rating. The gold part of the gradient ends at that exact point, so 4.7 fills most of the fifth star.

Does the star rating need JavaScript?

No. Both versions are plain HTML and CSS. The clickable input uses radio buttons, so it works inside a normal form with no script.

Is the clickable star rating accessible?

It uses real radio buttons with labels, so keyboard and screen reader users can choose a rating. Each star has a title, and the focused star shows an outline.

Will CSS stars show star ratings in Google search results?

No. Stars drawn with CSS are just a picture on your page. Google only shows review stars in some cases, based on structured data and its own rules. A business's own reviews on its own site usually do not qualify.

Can I change the star color?

Yes. Pick a star color and an empty star color in the tool. The colors are written straight into the CSS, so you can change them later too.

How do I show my real Google rating with stars?

You can type your Google rating into the tool. It will not update by itself, though. A Google reviews widget shows your live rating and reviews and keeps them up to date.

Is this star rating generator free?

Yes. It is free, needs no account and runs in your browser. Nothing you type is sent to our server.

Show your live Google rating

Put your real Google stars and reviews on your website. It updates on its own. Free plan available.

Related reading