CSS Star Rating: 16 Examples, No JavaScript Needed

A CSS star rating comes in two kinds that look almost the same. Some stars only report a score, others collect one, and HTML and CSS alone can handle both.

Below are 16 CSS star rating examples you can try and copy, followed by a guide to fractional fills, radio inputs, accessibility and AggregateRating markup.

By Bogdan Sandu · Updated October 28, 2026

Interactive star rating inputs

Ratings that collect a score. Every one is a group of radio buttons in a fieldset, kept in natural order from one star to five, so the arrow keys move the way the stars read and the value submits with a normal form.

Classic five-star radio rating

  • radio group
  • :has() sibling fill
  • hover preview
How was your stay at Larkspur Inn?

Your rating is shared with the hotel and shown on its public page.

Click a star, or Tab into the group and use the arrow keys.

Five radio inputs sit before their labels in order, one to five. The checked label and every label before it fill through two separate rules, input:checked + label and label:has(~ input:checked), so a browser without :has() still colors the chosen star. While the pointer is over the row, the checked fill resets and the hovered star plus the stars before it take over.

View code
.sr-c {
  --sr-c-fill: #f5a524;
  --sr-c-line: #b45309;
  --sr-c-empty: #6b7280;
  width: min(100%, 360px);
  padding: 28px 24px 22px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 14px 34px rgba(17, 24, 39, .08);
  color: #1f2430;
  text-align: center;
}
.sr-c__set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.sr-c__legend {
  margin: 0 auto 12px;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.35;
}
.sr-c__stars {
  position: relative;
  display: inline-flex;
}
.sr-c__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-c__star {
  display: block;
  padding: 4px;
  border-radius: 10px;
  cursor: pointer;
}
.sr-c__star svg {
  display: block;
  width: 36px;
  height: 36px;
  fill: transparent;
  stroke: var(--sr-c-empty);
  stroke-width: 1.6;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-c__in:checked + .sr-c__star svg {
  fill: var(--sr-c-fill);
  stroke: var(--sr-c-line);
}
.sr-c__star:has(~ .sr-c__in:checked) svg {
  fill: var(--sr-c-fill);
  stroke: var(--sr-c-line);
}
@media (hover: hover) {
  .sr-c__stars:hover .sr-c__star svg {
    fill: transparent;
    stroke: var(--sr-c-empty);
  }
  .sr-c__stars .sr-c__star:hover svg,
  .sr-c__stars .sr-c__star:has(~ .sr-c__star:hover) svg {
    fill: var(--sr-c-fill);
    stroke: var(--sr-c-line);
  }
}
.sr-c__in:focus-visible + .sr-c__star {
  outline: 3px solid #1d4ed8;
  outline-offset: 1px;
}
.sr-c__foot {
  margin: 14px 0 0;
  font-size: .85rem;
  line-height: 1.45;
  color: #555b66;
}

Half-star input with ten radios

  • 10 radio inputs
  • overflow clip halves
  • 24px targets
Rate the course: Intro to Letterpress

No rating yet

Click a star, or Tab into the group and use the arrow keys.

Half stars need twice the inputs: ten radios valued 0.5 to 5, each label showing one half of a star by clipping a full-width SVG. Every half is 24 pixels wide, so each target still meets the 24 by 24 minimum in WCAG 2.2, which is why the stars are 48 pixels across. A five-line script only writes the chosen value into the readout.

View code
.sr-h {
  --sr-h-fill: #0d9488;
  --sr-h-line: #0f5f58;
  --sr-h-empty: #687280;
  width: min(100%, 340px);
  padding: 24px 20px;
  border: 1px solid #d7e3e0;
  border-radius: 16px;
  background: #f8fbfa;
  color: #14302c;
  text-align: center;
}
.sr-h__set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.sr-h__legend {
  margin: 0 auto 10px;
  padding: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
}
.sr-h__stars {
  position: relative;
  display: inline-flex;
}
.sr-h__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-h__half {
  display: block;
  width: 24px;
  height: 48px;
  overflow: hidden;
  cursor: pointer;
}
.sr-h__half svg {
  display: block;
  width: 48px;
  height: 48px;
  fill: transparent;
  stroke: var(--sr-h-empty);
  stroke-width: 1.4;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-h__half--end svg {
  margin-left: -24px;
}
.sr-h__in:checked + .sr-h__half svg {
  fill: var(--sr-h-fill);
  stroke: var(--sr-h-line);
}
.sr-h__half:has(~ .sr-h__in:checked) svg {
  fill: var(--sr-h-fill);
  stroke: var(--sr-h-line);
}
@media (hover: hover) {
  .sr-h__stars:hover .sr-h__half svg {
    fill: transparent;
    stroke: var(--sr-h-empty);
  }
  .sr-h__stars .sr-h__half:hover svg,
  .sr-h__stars .sr-h__half:has(~ .sr-h__half:hover) svg {
    fill: var(--sr-h-fill);
    stroke: var(--sr-h-line);
  }
}
.sr-h__in:focus-visible + .sr-h__half {
  outline: 3px solid #7c3aed;
  outline-offset: -3px;
  border-radius: 6px;
}
.sr-h__out {
  margin: 10px 0 0;
  font-size: .95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #36524e;
}

Rating with text labels, announced live

  • aria-live="polite"
  • :has() color steps
  • word labels
How easy was checkout?

Pick a score from Poor to Excellent

Click a star, or Tab into the group and use the arrow keys.

Each star carries a word as well as a number, from Poor to Excellent, so the scale means the same thing to everyone. A polite live region repeats the choice as text for anyone who cannot see the caption change, and :has() shifts the fill color from red to green as the score rises, on top of the shape change.

View code
.sr-t {
  --sr-t-fill: #f59e0b;
  --sr-t-line: #92400e;
  --sr-t-empty: #6b6f7b;
  width: min(100%, 340px);
  padding: 24px 22px 20px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 0 #e3e5ea, 0 10px 28px rgba(28, 33, 48, .07);
  color: #1c2130;
}
.sr-t:has(.sr-t__in[value="1"]:checked) { --sr-t-fill: #ef4444; --sr-t-line: #991b1b; }
.sr-t:has(.sr-t__in[value="2"]:checked) { --sr-t-fill: #f97316; --sr-t-line: #9a3412; }
.sr-t:has(.sr-t__in[value="3"]:checked) { --sr-t-fill: #eab308; --sr-t-line: #854d0e; }
.sr-t:has(.sr-t__in[value="4"]:checked) { --sr-t-fill: #84cc16; --sr-t-line: #3f6212; }
.sr-t:has(.sr-t__in[value="5"]:checked) { --sr-t-fill: #22c55e; --sr-t-line: #166534; }
.sr-t__set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.sr-t__legend {
  margin: 0 0 12px;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.sr-t__stars {
  position: relative;
  display: flex;
  justify-content: space-between;
}
.sr-t__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-t__star {
  display: block;
  padding: 5px;
  border-radius: 10px;
  cursor: pointer;
}
.sr-t__star svg {
  display: block;
  width: 40px;
  height: 40px;
  fill: transparent;
  stroke: var(--sr-t-empty);
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: fill .2s, stroke .2s;
}
.sr-t__in:checked + .sr-t__star svg {
  fill: var(--sr-t-fill);
  stroke: var(--sr-t-line);
}
.sr-t__star:has(~ .sr-t__in:checked) svg {
  fill: var(--sr-t-fill);
  stroke: var(--sr-t-line);
}
.sr-t__in:focus-visible + .sr-t__star {
  outline: 3px solid #2563eb;
  outline-offset: 0;
}
.sr-t__scale {
  display: flex;
  justify-content: space-between;
  margin: 4px 0 0;
  font-size: .78rem;
  color: #5b6070;
}
.sr-t__live {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f3f4f7;
  font-size: .92rem;
  font-weight: 600;
  color: #50566a;
  text-align: center;
}
.sr-t--set .sr-t__live {
  color: #1c2130;
}

Rating with a clear button

  • button type="reset"
  • :has() state text
  • form

The Long Commute

Episode 42: Night trains of Europe

Your rating

Not rated yetRating saved to your library

Click a star, or Tab into the group and use the arrow keys.

Once a radio in a group is checked, the keyboard cannot uncheck it, so a rating needs an explicit way back to no answer. A reset button inside the form does it without script, because no radio starts checked. A group with nothing checked is left out of the submitted data, which the server can read as not rated.

View code
.sr-r {
  --sr-r-fill: #7c3aed;
  --sr-r-line: #4c1d95;
  --sr-r-empty: #6e6880;
  width: min(100%, 390px);
  margin: 0;
  padding: 20px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(46, 16, 101, .1);
  color: #221b33;
}
.sr-r__head {
  display: flex;
  gap: 14px;
  align-items: center;
}
.sr-r__art {
  flex: none;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: #2e1065;
  box-shadow: inset 0 -18px 0 #f59e0b, inset 0 -26px 0 #2e1065, inset 0 -30px 0 #c4b5fd;
}
.sr-r__show {
  margin: 0;
  font-weight: 700;
}
.sr-r__ep {
  margin: 2px 0 0;
  font-size: .86rem;
  color: #5b5470;
}
.sr-r__set {
  min-width: 0;
  margin: 16px 0 0;
  padding: 14px 0 0;
  border: 0;
  border-top: 1px solid #ece8f4;
}
.sr-r__legend {
  float: left;
  width: 100%;
  margin: 0 0 6px;
  padding: 0;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: #5b5470;
}
.sr-r__row {
  clear: both;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
}
.sr-r__stars {
  position: relative;
  display: flex;
}
.sr-r__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-r__star {
  display: block;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
}
.sr-r__star svg {
  display: block;
  width: 30px;
  height: 30px;
  fill: transparent;
  stroke: var(--sr-r-empty);
  stroke-width: 1.6;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-r__in:checked + .sr-r__star svg {
  fill: var(--sr-r-fill);
  stroke: var(--sr-r-line);
}
.sr-r__star:has(~ .sr-r__in:checked) svg {
  fill: var(--sr-r-fill);
  stroke: var(--sr-r-line);
}
@media (hover: hover) {
  .sr-r__stars:hover .sr-r__star svg {
    fill: transparent;
    stroke: var(--sr-r-empty);
  }
  .sr-r__stars .sr-r__star:hover svg,
  .sr-r__stars .sr-r__star:has(~ .sr-r__star:hover) svg {
    fill: var(--sr-r-fill);
    stroke: var(--sr-r-line);
  }
}
.sr-r__in:focus-visible + .sr-r__star {
  outline: 3px solid #0e7490;
  outline-offset: 0;
}
.sr-r__clear {
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid #c9c1db;
  border-radius: 999px;
  background: #fff;
  color: #3b2f57;
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.sr-r__clear:hover {
  background: #f3effb;
}
.sr-r__clear:focus-visible {
  outline: 3px solid #0e7490;
  outline-offset: 2px;
}
.sr-r:not(:has(.sr-r__in:checked)) .sr-r__clear {
  color: #6e6880;
}
.sr-r__state {
  margin: 12px 0 0;
  font-size: .86rem;
  color: #5b5470;
}
.sr-r__on {
  display: none;
}
.sr-r:has(.sr-r__in:checked) .sr-r__on {
  display: inline;
  color: #4c1d95;
  font-weight: 600;
}
.sr-r:has(.sr-r__in:checked) .sr-r__off {
  display: none;
}

Large touch rating in a bottom sheet

  • grid 1fr columns
  • 64px targets
  • touch-action

Marta V.

Grey hatchback, 14 min, 5.2 km

How was your ride with Marta?

Click a star, or Tab into the group and use the arrow keys.

A post-ride screen where the stars are the main control, so each one gets a full fifth of the sheet and a target well above 44 pixels. The grid columns shrink with the phone instead of overflowing, and touch-action: manipulation removes the double-tap zoom delay on quick taps.

View code
.sr-l {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: #e7ebe1;
  color: #111827;
}
.sr-l__map {
  display: block;
  flex: 1;
  width: 100%;
  min-height: 0;
}
.sr-l__sheet {
  padding: 18px 18px 20px;
  border-radius: 22px 22px 0 0;
  background: #fff;
  box-shadow: 0 -8px 24px rgba(17, 24, 39, .12);
}
.sr-l__driver {
  display: flex;
  gap: 12px;
  align-items: center;
}
.sr-l__avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #1e293b;
  color: #fff;
  font-size: .85rem;
  font-weight: 700;
}
.sr-l__name {
  margin: 0;
  font-weight: 700;
}
.sr-l__trip {
  margin: 1px 0 0;
  font-size: .82rem;
  color: #4b5563;
}
.sr-l__set {
  min-width: 0;
  margin: 14px 0 0;
  padding: 0;
  border: 0;
}
.sr-l__legend {
  margin: 0 0 4px;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 700;
}
.sr-l__stars {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.sr-l__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-l__star {
  display: grid;
  place-items: center;
  min-height: 64px;
  border-radius: 14px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.sr-l__star svg {
  display: block;
  width: min(48px, 100%);
  height: auto;
  aspect-ratio: 1;
  fill: #e5e7eb;
  stroke: #6b7280;
  stroke-width: 1.3;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-l__in:checked + .sr-l__star svg {
  fill: #111827;
  stroke: #111827;
}
.sr-l__star:has(~ .sr-l__in:checked) svg {
  fill: #111827;
  stroke: #111827;
}
.sr-l__in:focus-visible + .sr-l__star {
  outline: 3px solid #1d4ed8;
  outline-offset: -3px;
}
.sr-l__done {
  display: block;
  width: 100%;
  min-height: 52px;
  margin-top: 12px;
  border: 0;
  border-radius: 14px;
  background: #111827;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.sr-l__done:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 3px;
}
.sr-l:not(:has(.sr-l__in:checked)) .sr-l__done {
  background: #e5e7eb;
  color: #374151;
}

Read-only rating displays

Ratings that only report a score from somewhere else. There is nothing to click, so there are no inputs: one custom property holds the value, CSS turns it into a partial fill, and real text carries the number for screen readers.

Fractional rating with a width clip

  • --rating custom property
  • overflow: hidden
  • role="img"

Pocket Herbarium

2,184 ratings

Two identical rows of SVG stars are stacked, and the top, filled row is cut to calc(var(--sr-f-rating) / 5 * 100%) with overflow: hidden, so 4.3 shows as 86 percent of the row. The stars have no gap between them, which keeps the percentage of the row equal to the percentage of the stars. The wrapper is role="img" with the label Rated 4.3 out of 5, which makes the drawn stars presentational.

View code
.sr-f {
  display: flex;
  gap: 18px;
  align-items: center;
  width: min(100%, 340px);
  padding: 22px 24px;
  border-radius: 20px;
  background: #fffaf0;
  box-shadow: inset 0 0 0 1px #f1e3c4;
  color: #2b2116;
}
.sr-f__score {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 3.6rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -.02em;
}
.sr-f__body {
  min-width: 0;
}
.sr-f__app {
  margin: 0 0 4px;
  font-size: .9rem;
  font-weight: 700;
}
.sr-f__stars {
  position: relative;
  display: inline-block;
  font-size: 30px;
  line-height: 0;
  vertical-align: middle;
}
.sr-f__row {
  display: flex;
}
.sr-f__row svg {
  flex: none;
  width: 1em;
  height: 1em;
  fill: #efe4cc;
  stroke: #8a7449;
  stroke-width: 1.2;
  stroke-linejoin: round;
}
.sr-f__row--fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--sr-f-rating) / 5 * 100%);
  overflow: hidden;
}
.sr-f__row--fill svg {
  fill: #e0911b;
  stroke: #8c4f05;
}
.sr-f__count {
  margin: 6px 0 0;
  font-size: .85rem;
  color: #6a5a43;
}

Mask-image stars that follow currentColor

  • mask-image repeat-x
  • currentColor
  • color-mix()

Aerin Q2 headphones, by category

Sound
4.6 out of 5
Comfort
3.8 out of 5
Battery
4.1 out of 5
Call quality
2.7 out of 5

One empty span per rating: a star SVG is the mask, repeated five times across a 5em box, and the background is a hard-stop gradient from currentColor to a paler mix of it. Change color on the row and the stars follow, which is how each category here gets its own hue. The number stays as real text, so the span is hidden from screen readers.

View code
.sr-m {
  width: min(100%, 360px);
  padding: 22px 22px 14px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .07);
  color: #0f172a;
}
.sr-m__title {
  margin: 0 0 8px;
  font-weight: 700;
}
.sr-m__list {
  margin: 0;
}
.sr-m__item {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-top: 1px solid #eef0f4;
}
.sr-m__item dt {
  font-size: .95rem;
  color: #334155;
}
.sr-m__item dd {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0;
}
.sr-m__item--sound { color: #0f766e; }
.sr-m__item--comfort { color: #6d28d9; }
.sr-m__item--battery { color: #c2410c; }
.sr-m__item--calls { color: #be123c; }
.sr-m__stars {
  --sr-m-empty: #dfe3ea;
  --sr-m-star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2.94 6.08 6.56.82-4.82 4.52 1.24 6.58L12 17.3l-5.92 3.2 1.24-6.58L2.5 9.4l6.56-.82z'/%3E%3C/svg%3E");
  display: block;
  width: 5em;
  height: 1em;
  font-size: 22px;
  background: linear-gradient(90deg, currentColor calc(var(--sr-m-r) / 5 * 100%), var(--sr-m-empty) 0);
  -webkit-mask: var(--sr-m-star) 0 0 / 1em 1em repeat-x;
  mask: var(--sr-m-star) 0 0 / 1em 1em repeat-x;
}
@supports (color: color-mix(in srgb, red 50%, white)) {
  .sr-m__stars {
    --sr-m-empty: color-mix(in srgb, currentColor 22%, #fff);
  }
}
.sr-m__num {
  min-width: 2ch;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.sr-m__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

Product card rating with review count

  • mask stars
  • visible count
  • hidden context text
Yellow two-person tent pitched in deep snow below a mountain range

Northkit Ridge 2 four-season tent

Rated 4.4 out of 5, (89 reviews)

2.1 kg, sleeps two, snow skirt

$389

The pattern a shop listing needs: stars, the average and the review count on one line, all printed as visible text. If the page also carries AggregateRating markup, these are the numbers it has to match, because Google wants the rating visible to users. Hidden words turn the line into Rated 4.4 out of 5, 89 reviews for screen readers.

View code
.sr-pc {
  width: min(100%, 300px);
  overflow: hidden;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(20, 28, 40, .1);
  color: #18202b;
}
.sr-pc__img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.sr-pc__body {
  padding: 16px 18px 18px;
}
.sr-pc__name {
  margin: 0;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  color: #18202b;
}
.sr-pc__rating {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 8px 0 0;
  font-size: .9rem;
}
.sr-pc__stars {
  --sr-pc-star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2.94 6.08 6.56.82-4.82 4.52 1.24 6.58L12 17.3l-5.92 3.2 1.24-6.58L2.5 9.4l6.56-.82z'/%3E%3C/svg%3E");
  display: block;
  width: 5em;
  height: 1em;
  font-size: 18px;
  background: linear-gradient(90deg, #d97706 calc(var(--sr-pc-r) / 5 * 100%), #d6d9de 0);
  -webkit-mask: var(--sr-pc-star) 0 0 / 1em 1em repeat-x;
  mask: var(--sr-pc-star) 0 0 / 1em 1em repeat-x;
}
.sr-pc__num {
  font-weight: 700;
}
.sr-pc__count {
  color: #4b5563;
}
.sr-pc__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-pc__meta {
  margin: 6px 0 0;
  font-size: .85rem;
  color: #4b5563;
}
.sr-pc__buy {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
}
.sr-pc__price {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}
.sr-pc__btn {
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: #1f3a2e;
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s;
}
.sr-pc__btn:hover {
  background: #2d5242;
}
.sr-pc__btn:focus-visible {
  outline: 3px solid #d97706;
  outline-offset: 2px;
}

Review summary with rating bars

  • grid rows
  • bar width from --pct
  • text percentages

4.6

out of 5, from 1,208 ratings

  • 5 stars74%
  • 4 stars16%
  • 3 stars5%
  • 2 stars2%
  • 1 star3%

The average sits next to a distribution: one row per star level, with a bar whose width comes from a custom property and the percentage printed beside it. The bars are decoration for the eye, so they are hidden from screen readers, and each list item reads as 5 stars, 74 percent.

View code
.sr-s {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 24px;
  align-items: center;
  width: min(100%, 460px);
  padding: 22px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 0 0 1px #e6e2da;
  color: #22201c;
}
.sr-s__avg {
  flex: 0 0 auto;
  text-align: center;
}
.sr-s__big {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 3rem;
  font-weight: 600;
  line-height: 1;
}
.sr-s__stars {
  --sr-s-star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2.94 6.08 6.56.82-4.82 4.52 1.24 6.58L12 17.3l-5.92 3.2 1.24-6.58L2.5 9.4l6.56-.82z'/%3E%3C/svg%3E");
  display: block;
  width: 5em;
  height: 1em;
  margin: 8px auto 0;
  font-size: 20px;
  background: linear-gradient(90deg, #c2410c calc(var(--sr-s-r) / 5 * 100%), #e7ddd3 0);
  -webkit-mask: var(--sr-s-star) 0 0 / 1em 1em repeat-x;
  mask: var(--sr-s-star) 0 0 / 1em 1em repeat-x;
}
.sr-s__total {
  margin: 6px 0 0;
  font-size: .82rem;
  color: #5e584e;
}
.sr-s__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-s__bars {
  flex: 1 1 220px;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.sr-s__bars li {
  display: grid;
  grid-template-columns: 4.2em 1fr 2.6em;
  gap: 10px;
  align-items: center;
  font-size: .85rem;
}
.sr-s__lvl {
  color: #3d3830;
}
.sr-s__bar {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #efe9e1;
}
.sr-s__bar span {
  display: block;
  width: var(--sr-s-p);
  height: 100%;
  border-radius: inherit;
  background: #c2410c;
}
.sr-s__pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #5e584e;
}

Read-only ratings in a comparison table

  • table caption
  • mask stars
  • tabular-nums
Trail running shoes, spring test
ShoeWeightRating (of 5)
Pacer Trail 3280 g4.7
Ridgeline XT310 g4.2
Fellwalker 2295 g3.9
Scree Lite255 g3.4

Inside a table the number does the work and the stars are a quick visual scan. The column header says out of 5 once, so every cell only needs the value, and the star span stays aria-hidden. A real caption names the table, and the wrapper scrolls instead of breaking the layout if a narrow screen runs out of room.

View code
.sr-tb {
  width: min(100%, 480px);
  padding: 6px 6px 2px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 8px 26px rgba(30, 41, 59, .08);
  color: #1e293b;
}
.sr-tb__scroll {
  overflow-x: auto;
}
.sr-tb__table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
  font-variant-numeric: tabular-nums;
}
.sr-tb__cap {
  padding: 10px 10px 8px;
  font-weight: 700;
  text-align: left;
}
.sr-tb__table th,
.sr-tb__table td {
  padding: 10px;
  border-top: 1px solid #e8ecf2;
  text-align: left;
  white-space: nowrap;
}
.sr-tb__table thead th {
  border-top: 0;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: #55627a;
}
.sr-tb__table tbody th {
  font-weight: 600;
  white-space: normal;
}
.sr-tb__table td:last-child {
  font-weight: 700;
}
.sr-tb__stars {
  --sr-tb-star: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2.94 6.08 6.56.82-4.82 4.52 1.24 6.58L12 17.3l-5.92 3.2 1.24-6.58L2.5 9.4l6.56-.82z'/%3E%3C/svg%3E");
  display: inline-block;
  width: 5em;
  height: 1em;
  margin-right: 6px;
  font-size: 13px;
  vertical-align: -1px;
  background: linear-gradient(90deg, #2563eb calc(var(--sr-tb-r) / 5 * 100%), #d5dbe5 0);
  -webkit-mask: var(--sr-tb-star) 0 0 / 1em 1em repeat-x;
  mask: var(--sr-tb-star) 0 0 / 1em 1em repeat-x;
}

Dark, right-to-left and animated ratings

The same radio pattern under three kinds of pressure: a dark interface, a right-to-left language and a selection animation that only runs for people who have not asked for reduced motion.

Dark theme episode rating

  • color-scheme: dark
  • outline vs solid
  • hover preview

Low Tide

Season 2, 8 episodes

Rate this season

Click a star, or Tab into the group and use the arrow keys.

On a dark surface the empty stars are outlines in a mid grey that still clears 3:1 against the card, and the filled stars switch to a solid shape, so the state never depends on hue alone. color-scheme: dark keeps any native parts of the control dark, and the focus ring is a light blue that stands out on near-black.

View code
.sr-d {
  display: flex;
  gap: 16px;
  align-items: center;
  width: min(100%, 400px);
  padding: 20px;
  border: 1px solid #2a2f3c;
  border-radius: 16px;
  background: #161922;
  color: #eef0f6;
  color-scheme: dark;
}
.sr-d__poster {
  display: block;
  flex: none;
  width: clamp(64px, 22%, 96px);
  height: auto;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  object-fit: cover;
}
.sr-d__main {
  flex: 1 1 auto;
  min-width: 0;
}
.sr-d__show {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
}
.sr-d__ep {
  margin: 4px 0 0;
  font-size: .85rem;
  color: #a9b0c2;
}
.sr-d__set {
  min-width: 0;
  margin: 14px 0 0;
  padding: 0;
  border: 0;
}
.sr-d__legend {
  margin: 0 0 4px;
  padding: 0;
  font-size: .85rem;
  font-weight: 600;
  color: #cfd4e0;
}
.sr-d__stars {
  position: relative;
  display: flex;
  margin-left: -4px;
}
.sr-d__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-d__star {
  display: block;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
}
.sr-d__star svg {
  display: block;
  width: 32px;
  height: 32px;
  fill: transparent;
  stroke: #8b93a7;
  stroke-width: 1.6;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-d__in:checked + .sr-d__star svg {
  fill: #fbbf24;
  stroke: #fbbf24;
}
.sr-d__star:has(~ .sr-d__in:checked) svg {
  fill: #fbbf24;
  stroke: #fbbf24;
}
@media (hover: hover) {
  .sr-d__stars:hover .sr-d__star svg {
    fill: transparent;
    stroke: #8b93a7;
  }
  .sr-d__stars .sr-d__star:hover svg,
  .sr-d__stars .sr-d__star:has(~ .sr-d__star:hover) svg {
    fill: #fbbf24;
    stroke: #fbbf24;
  }
}
.sr-d__in:focus-visible + .sr-d__star {
  outline: 3px solid #93c5fd;
  outline-offset: 0;
}

Right-to-left rating in Arabic

  • dir="rtl"
  • inset-inline-start
  • logical fill
كيف كانت تجربتك؟

Click a star, or Tab into the group and use the arrow keys.

With dir="rtl" on the wrapper, a flex row starts on the right, so star one sits on the right and the fill grows leftward with no extra CSS. The read-only score uses inset-inline-start for its filled layer instead of left, so it also fills from the right. The same markup in a left-to-right page fills from the left.

View code
.sr-a {
  width: min(100%, 340px);
  padding: 22px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(22, 50, 46, .09);
  color: #13302b;
  font-family: system-ui, "Segoe UI", Tahoma, sans-serif;
}
.sr-a__score {
  display: flex;
  gap: 10px;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid #e3ece9;
}
.sr-a__stars {
  position: relative;
  display: inline-block;
  font-size: 24px;
  line-height: 0;
}
.sr-a__row {
  display: flex;
}
.sr-a__row svg {
  flex: none;
  width: 1em;
  height: 1em;
  fill: #dfe9e6;
  stroke: #6b8781;
  stroke-width: 1.2;
  stroke-linejoin: round;
}
.sr-a__row--fill {
  position: absolute;
  inset-block: 0;
  inset-inline-start: 0;
  width: calc(var(--sr-a-rating) / 5 * 100%);
  overflow: hidden;
}
.sr-a__row--fill svg {
  fill: #0f766e;
  stroke: #0b4f49;
}
.sr-a__num {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}
.sr-a__set {
  min-width: 0;
  margin: 14px 0 0;
  padding: 0;
  border: 0;
}
.sr-a__legend {
  margin: 0 0 6px;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 700;
}
.sr-a__input {
  position: relative;
  display: flex;
}
.sr-a__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-a__star {
  display: block;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
}
.sr-a__star svg {
  display: block;
  width: 36px;
  height: 36px;
  fill: transparent;
  stroke: #5f7a74;
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-a__in:checked + .sr-a__star svg {
  fill: #0f766e;
  stroke: #0b4f49;
}
.sr-a__star:has(~ .sr-a__in:checked) svg {
  fill: #0f766e;
  stroke: #0b4f49;
}
@media (hover: hover) {
  .sr-a__input:hover .sr-a__star svg {
    fill: transparent;
    stroke: #5f7a74;
  }
  .sr-a__input .sr-a__star:hover svg,
  .sr-a__input .sr-a__star:has(~ .sr-a__star:hover) svg {
    fill: #0f766e;
    stroke: #0b4f49;
  }
}
.sr-a__in:focus-visible + .sr-a__star {
  outline: 3px solid #b45309;
  outline-offset: 0;
}

Animated star pop on select

  • @keyframes
  • prefers-reduced-motion
  • ::after ring

Glass Harbour

Mira Sol, from the album Tidewater

Rate this track

Click a star, or Tab into the group and use the arrow keys.

The chosen star scales up and back with a little overshoot while a ring expands and fades behind it. The animation is attached to input:checked + label, so it plays once each time the selection lands on a new star. Both keyframe rules sit inside prefers-reduced-motion: no-preference, so people who asked for less motion get the color change only.

View code
.sr-p {
  width: min(100%, 340px);
  padding: 20px 22px 18px;
  border-radius: 20px;
  background: #fff6ea;
  box-shadow: inset 0 0 0 1px #f3dcc0;
  color: #3a1f0d;
}
.sr-p__track {
  display: flex;
  gap: 14px;
  align-items: center;
}
.sr-p__cover {
  flex: none;
  width: 58px;
  height: 58px;
  border-radius: 12px;
  background: #1e3a5f;
  box-shadow: inset 20px -14px 0 -8px #ea580c, inset -10px 20px 0 -4px #fde68a;
}
.sr-p__title {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.2rem;
  font-weight: 600;
}
.sr-p__artist {
  margin: 2px 0 0;
  font-size: .85rem;
  color: #6b4a33;
}
.sr-p__set {
  min-width: 0;
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}
.sr-p__legend {
  margin: 0 0 4px;
  padding: 0;
  font-size: .85rem;
  font-weight: 700;
  color: #6b4a33;
}
.sr-p__stars {
  position: relative;
  display: flex;
  margin-left: -5px;
}
.sr-p__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-p__star {
  position: relative;
  display: block;
  padding: 5px;
  border-radius: 50%;
  color: #ea580c;
  cursor: pointer;
}
.sr-p__star::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px solid currentColor;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.sr-p__star svg {
  position: relative;
  display: block;
  width: 36px;
  height: 36px;
  fill: transparent;
  stroke: #8a6a55;
  stroke-width: 1.5;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-p__in:checked + .sr-p__star svg {
  fill: #ea580c;
  stroke: #9a3412;
}
.sr-p__star:has(~ .sr-p__in:checked) svg {
  fill: #ea580c;
  stroke: #9a3412;
}
@media (hover: hover) {
  .sr-p__stars:hover .sr-p__star svg {
    fill: transparent;
    stroke: #8a6a55;
  }
  .sr-p__stars .sr-p__star:hover svg,
  .sr-p__stars .sr-p__star:has(~ .sr-p__star:hover) svg {
    fill: #ea580c;
    stroke: #9a3412;
  }
}
.sr-p__in:focus-visible + .sr-p__star {
  outline: 3px solid #1e3a5f;
  outline-offset: -2px;
}
@media (prefers-reduced-motion: no-preference) {
  .sr-p__in:checked + .sr-p__star svg {
    animation: sr-p-pop .45s cubic-bezier(.34, 1.56, .64, 1);
  }
  .sr-p__in:checked + .sr-p__star::after {
    animation: sr-p-ring .55s ease-out;
  }
  @keyframes sr-p-pop {
    0% { transform: scale(1); }
    40% { transform: scale(1.35); }
    100% { transform: scale(1); }
  }
  @keyframes sr-p-ring {
    0% { opacity: .9; transform: scale(.4); }
    100% { opacity: 0; transform: scale(1.35); }
  }
}

Hearts, faces and 0 to 10 scales

Stars are not the only scale. These three swap the icon or the range but keep the same radio group underneath, including a face scale drawn in SVG and a 0 to 10 likelihood question.

Hearts and thumbs instead of stars

  • heart SVG
  • two-option radio group
  • pill toggles

Smoky tomato shakshuka

Serves 4, 35 minutes

How much did you love it?
Would you make it again?

A recipe card with two different questions. The hearts are the same cumulative five-step pattern with a different shape. The thumbs are a separate two-option radio group, because yes and no are a choice, not a scale, and each option carries a visible word so the meaning does not depend on the icon.

View code
.sr-k {
  width: min(100%, 340px);
  padding: 22px;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 0 0 1px #f2dfe3, 0 14px 30px rgba(136, 19, 55, .08);
  color: #2a1418;
}
.sr-k__dish {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.2;
}
.sr-k__by {
  margin: 4px 0 0;
  font-size: .85rem;
  color: #6b4e54;
}
.sr-k__set {
  min-width: 0;
  margin: 16px 0 0;
  padding: 0;
  border: 0;
}
.sr-k__set--help {
  padding-top: 14px;
  border-top: 1px solid #f3e4e7;
}
.sr-k__legend {
  margin: 0 0 6px;
  padding: 0;
  font-size: .9rem;
  font-weight: 700;
}
.sr-k__hearts,
.sr-k__thumbs {
  position: relative;
  display: flex;
}
.sr-k__hearts {
  margin-left: -4px;
}
.sr-k__thumbs {
  gap: 10px;
}
.sr-k__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-k__heart {
  display: block;
  padding: 4px;
  border-radius: 8px;
  cursor: pointer;
}
.sr-k__heart svg {
  display: block;
  width: 34px;
  height: 34px;
  fill: transparent;
  stroke: #8d6b72;
  stroke-width: 1.6;
  stroke-linejoin: round;
  transition: fill .15s, stroke .15s;
}
.sr-k__in:checked + .sr-k__heart svg {
  fill: #e11d48;
  stroke: #9f1239;
}
.sr-k__heart:has(~ .sr-k__in:checked) svg {
  fill: #e11d48;
  stroke: #9f1239;
}
@media (hover: hover) {
  .sr-k__hearts:hover .sr-k__heart svg {
    fill: transparent;
    stroke: #8d6b72;
  }
  .sr-k__hearts .sr-k__heart:hover svg,
  .sr-k__hearts .sr-k__heart:has(~ .sr-k__heart:hover) svg {
    fill: #e11d48;
    stroke: #9f1239;
  }
}
.sr-k__in:focus-visible + .sr-k__heart,
.sr-k__opt:focus-visible + .sr-k__pill {
  outline: 3px solid #1d4ed8;
  outline-offset: 1px;
}
.sr-k__pill {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 0 18px 0 14px;
  border: 1.5px solid #d8c3c8;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.sr-k__pill svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linejoin: round;
}
.sr-k__down {
  transform: scaleY(-1);
}
.sr-k__pill:hover {
  border-color: #9f1239;
}
.sr-k__opt:checked + .sr-k__pill {
  border-color: #9f1239;
  background: #9f1239;
  color: #fff;
}

Face scale drawn in SVG

  • inline SVG faces
  • visible word labels
  • single-choice highlight
How did the onboarding call go?

Five faces from a deep frown to a wide smile, drawn as inline SVG strokes so they inherit currentColor and stay emoji-free and identical across platforms. Unlike stars, the scale is not cumulative, so only the checked face lights up. Each face has a visible word under it, which doubles as its accessible name.

View code
.sr-e {
  width: min(100%, 380px);
  padding: 22px 18px;
  border-radius: 18px;
  background: #fbfaf7;
  box-shadow: inset 0 0 0 1px #e6e1d6;
  color: #26231c;
}
.sr-e__set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.sr-e__legend {
  margin: 0 auto 12px;
  padding: 0;
  font-size: 1.02rem;
  font-weight: 700;
  text-align: center;
}
.sr-e__faces {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}
.sr-e__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-e__face {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 8px 2px 6px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
  color: #5f5a4e;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.sr-e__face svg {
  width: min(42px, 100%);
  height: auto;
  aspect-ratio: 1;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
}
.sr-e__eye {
  fill: currentColor;
  stroke: none;
}
.sr-e__face:hover {
  background: #f0ece3;
  color: #26231c;
}
.sr-e__in:checked + .sr-e__face--1 { background: #fee2e2; color: #991b1b; }
.sr-e__in:checked + .sr-e__face--2 { background: #ffedd5; color: #9a3412; }
.sr-e__in:checked + .sr-e__face--3 { background: #fef3c7; color: #854d0e; }
.sr-e__in:checked + .sr-e__face--4 { background: #dcfce7; color: #166534; }
.sr-e__in:checked + .sr-e__face--5 { background: #d1fae5; color: #065f46; }
.sr-e__in:checked + .sr-e__face svg {
  stroke-width: 2;
}
.sr-e__in:focus-visible + .sr-e__face {
  outline: 3px solid #1d4ed8;
  outline-offset: 1px;
}

NPS 0 to 10 likelihood scale

  • 11-column grid
  • :has() score bands
  • conditional follow-up
How likely are you to recommend Fieldnote to a friend or colleague?

The Net Promoter question as eleven radios in one grid row, sized so all eleven fit a phone without wrapping. The end labels are hidden from screen readers and repeated in the first and last radio names instead. After a score is picked, :has() colors it by band (0 to 6, 7 to 8, 9 to 10) and reveals a follow-up question without any script.

View code
.sr-n {
  width: min(100%, 460px);
  padding: 22px 18px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .08);
  color: #111827;
}
.sr-n__set {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.sr-n__legend {
  margin: 0 0 14px;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
}
.sr-n__scale {
  position: relative;
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  gap: 4px;
}
.sr-n__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.sr-n__num {
  display: grid;
  place-items: center;
  min-width: 24px;
  min-height: 44px;
  border: 1px solid #cbd2dc;
  border-radius: 8px;
  background: #f8fafc;
  font-size: .9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.sr-n__num:hover {
  border-color: #475569;
  background: #eef2f7;
}
.sr-n__in:checked + .sr-n__num {
  border-color: #b91c1c;
  background: #b91c1c;
  color: #fff;
}
.sr-n__in--mid:checked + .sr-n__num {
  border-color: #a16207;
  background: #a16207;
}
.sr-n__in--top:checked + .sr-n__num {
  border-color: #15803d;
  background: #15803d;
}
.sr-n__in:focus-visible + .sr-n__num {
  outline: 3px solid #1d4ed8;
  outline-offset: 2px;
}
.sr-n__ends {
  display: flex;
  justify-content: space-between;
  margin: 8px 0 0;
  font-size: .78rem;
  color: #4b5563;
}
.sr-n__follow {
  display: none;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #e5e7eb;
}
.sr-n:has(.sr-n__in:checked) .sr-n__follow {
  display: block;
}
.sr-n__qlabel {
  display: block;
  margin-bottom: 6px;
  font-size: .9rem;
  font-weight: 600;
}
.sr-n__why {
  box-sizing: border-box;
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #94a3b8;
  border-radius: 10px;
  font: inherit;
  font-size: .95rem;
  color: #111827;
  resize: vertical;
}
.sr-n__why:focus-visible {
  outline: 3px solid #1d4ed8;
  outline-offset: 1px;
}

Display rating or input rating: which one are you building?

Some stars only report a number, say 4.3 out of 5, that came from somewhere else. Others collect a fresh number from the visitor. Both turn a score into filled and empty stars, but the markup underneath has very little in common.

The read-only version needs no form control at all. A wrapper with an accessible name and a fill that matches the value is enough.

Collecting a score means a group of radio inputs. A widget walkthrough on iamkate.com points out that assistive software reads the group as radio buttons and standard keyboard interaction comes with it, no extra code.

Building that version from span elements and JavaScript click handlers is where most widgets go wrong, according to a 2026 theplusaddons guide. A span has no keyboard behavior and no form value, so both have to be rebuilt by hand. Nobody enjoys that part.

Five stars is the default, but the maximum is a value like any other. A 10-star scale works the same way as long as the markup, not the stylesheet, decides the star count.

An input rating counts among the interactive elements on a page, so it picks up focus and touch requirements that a display rating never has.

A product page showing an average needs the first version. A review form needs the second. Most pages end up with both, built separately.

Star shape methods compared: Unicode, SVG, mask, and icon fonts

Unicode gives the smallest build and inline SVG gives an exact brand shape. A mask is what handles partial fills in any color, and icon fonts rarely beat any of the three.

MethodColor and scalingFractional fillFails when
Unicode (U+2605, U+2606)Follows color and font-sizeNeeds gradient or overlayEach font draws its own star
Inline SVGExact shape, fill follows currentColorOverlay or stacked copiesFill is hard-coded in the file
clip-path or mask-imageAny background shows throughGradient behind the maskOlder Chrome needs -webkit-mask
Icon fontFollows color and font-sizeSame limits as UnicodeExtra font request for one glyph

The two Unicode characters used for ratings are U+2605 (black star, filled) and U+2606 (white star, outline). Both live in the Miscellaneous Symbols block (U+2600 to U+26FF), and U+2605 has been in Unicode since version 1.1 in 1993 (codepoints.net). Insert them with ::before and content: “\2605” and they pick up the text color automatically.

Neither one is a half star. A partial fill needs a gradient or overlay on top, which the next section covers.

Drawing the star as inline SVG gives an exact shape at any size, and fill: currentColor lets it inherit the text color. Where it goes wrong is a fill attribute baked into the file, because that blocks theming.

clip-path with polygon() takes straight-edged points, so rounded corners need path() or an SVG reference. mask-image takes an image instead, which means rounded stars work and a gradient background shows through the star shape.

Plotting polygon points by hand is slow, and a clip-path generator will output them from a visual shape.

On support, Chrome 120 (5 December 2023) was the last of the three engines to ship unprefixed mask, which is why Baseline dates the property to December 2023 (web-features project).

Font Awesome and Bootstrap Icons ship a star, and so does Material Symbols. Still, loading a font file for one glyph costs a request that inline SVG avoids.

Sizing stars with em units

Set font-size on the wrapper and size every star in em, so one declaration scales the whole row.

Unicode glyphs and icon fonts scale with font-size directly. Inline SVG needs a width and height of 1em, and a mask needs that same 1em on both mask-size and the element itself.

Em-based stars also follow the visitor’s text size settings.

Setting fill and empty colors with custom properties

Store both colors on the wrapper as –star-fill and –star-empty, and every technique reads them. A theme change then touches two lines.

Amber (#f5a524) for filled and light gray (#d4d4dc) for empty is the pair in the theplusaddons example. Light gray on a white background is low contrast, so check the empty color before shipping.

How to show a fractional rating like 3.7 out of 5

Divide the rating by the maximum, multiply by 100, and fill that share of the star row. For 3.7 out of 5 the fill is 74%, held in one custom property that whichever technique draws the stars reads.

The theplusaddons guide (2026) runs the same arithmetic. A 3.5 out of 5 fills 70%, and 4.3 fills 86%.

With Unicode stars, a linear-gradient with a hard stop at calc(var(–rating) / 5 * 100%) runs across the row. Add background-clip: text and a transparent text color, and the gradient gets cut to the shape of the glyphs.

Inline SVG works differently. The row of stars sits under an overlay whose width is the unfilled share (100% minus the fill), tinted with mix-blend-mode so the page background stays untouched.

A mask splits the job another way, with mask-image supplying the star tiles and a gradient background supplying the fill.

Hard-stop gradients are fiddly to write from scratch, and a gradient generator shows the stop positions before you copy them.

The “Fractional SVG stars with CSS” write-up (updated December 2021) documents a switch from stacked PNG overlays, which caused extra requests and CLS issues, to inline SVG with one computed overlay width.

Component libraries land in the same place. HeroUI Pro’s Rating exposes a –rating-partial variable for the width of its partial overlay, and Reka UI’s Rating exposes –reka-rating-item-step-width to clip each fractional step (both per their documentation). Whatever the tool, the number underneath is a percentage held in a custom property.

One thing breaks this. The gradient spans the whole row, gaps included, so unless the gap is zero (put the spacing inside each star as padding), 74% of the row is not 74% of the stars.

MDN also advises an @supports test for background-clip: text, with an accessible alternative where it fails, because the effect disappears on opaque text.

How to build a clickable CSS star rating without JavaScript

Five radio inputs sharing one name do most of the work. Hide the inputs visually, style each label as a star, and let :checked and :has() light them up. Selection, keyboard movement and form submission all come from the radio group, so there is nothing to wire up.

  1. Wrap five radio inputs in a fieldset with a legend, give them one shared name, and put each input before its label in natural order, 1 to 5.
  2. Hide each input with a visually-hidden rule, not display: none, which removes the radio from the tab order and the accessibility tree (MDN).
  3. Style each label as a star in the empty color, using a Unicode character or a mask.
  4. Add the fill color through two separate rules: input:checked + label, and label:has(~ input:checked).
  5. Add the hover preview through label:hover and label:has(~ label:hover), and reset the checked fill while the pointer is over the group.

Reversed order with row-reverse

Sibling combinators only look forward, so older builds list the highest rating first in the markup (Lea Verou, 2011) and flip the row on screen, often with flex-direction: row-reverse.

The cost shows up on the keyboard. A DEV Community write-up found that with row-reverse the arrow keys follow DOM order, not screen order, so Right Arrow lowers the rating. That is a bad surprise for anyone navigating without a mouse.

Natural order with :has()

With :has(), the inputs stay in natural order and label:has(~ input:checked) lights every label before the checked input.

Support starts at Chrome 105, Safari 15.4 and Firefox 121 (caniuse). The selector is Baseline Newly available since December 2023 (MDN), and Widely available as of the June 2026 Baseline digest (web.dev).

A browser without :has() drops the entire rule that contains it, which is why the :has() rule sits apart from the checked rule. With nothing checked yet, all five stars stay in the empty color.

Like most CSS hover effects, the preview has to override a state that already exists. While the pointer is over the group, the checked color resets to the empty color so the hovered stars win.

Range input as a one-element option

A native range input turns into a star rating with a mask and a few sizing lines, and Temani Afif’s CSS-Tip version reads the star count from the max attribute through typed attr(), which Safari does not support yet (MDN browser compat data). Setting min=”.5″, step=”.5″ and max=”5″ gives half stars, which a radio group cannot do without doubling its inputs.

A styled range slider still needs vendor pseudo-elements for the thumb, ::-webkit-slider-thumb in Chrome, Edge and Safari and ::-moz-range-thumb in Firefox. MDN lists both as non-standard.

Alvaro Montoro’s single-element version also keeps one inline JavaScript command, so it is not fully script-free.

Radios are the better pick when the rating goes into a form. If half stars matter more to you than markup semantics, go with the range input.

How to make a CSS star rating accessible

A display rating needs a text name, and an input rating needs labeled radio inputs. Both need a visible focus ring, stars with 3:1 contrast and a 24 by 24 pixel hit area. These fail independently, so a good-looking widget can still lock people out.

For a display rating, a span with role=”img” and an aria-label of “Rating: 4 out of 5 stars” is the exact pattern MDN’s img role page shows. It is ARIA doing a job no native element is built for, since HTML has no star rating element.

Descendants of role img are presentational, so the star glyphs inside stay silent and the label carries the value.

Material UI’s Rating component is a useful reference for the input side. It renders six radio buttons (one per star, plus a zero that is checked by default) with text labels such as “1 Star” and “2 Stars”, and keyboard behavior stays native (MUI documentation).

Wrap the group in a fieldset with a legend that asks the question. Keep each label’s text in the DOM, visually hidden, so every star announces as “3 stars” and not as an unnamed radio.

For focus, draw the ring on the label with input:focus-visible + label. W3C lists a removed or invisible focus indicator as failure F78 against SC 1.4.11, 2.4.7 and 2.4.13, and :focus-visible is Baseline Widely available (MDN).

W3C’s Understanding document for SC 1.4.11 uses a star rating as its failing example. Pale yellow (#FFF000) stars on white measure 1.2:1 against a required 3:1. A second example in the same document, stars outlined in black and filled yellow or white, fails SC 1.4.1 (Use of Color) rather than 1.4.11, because hue alone carries the value.

Passing versions use a solid fill against an outline, or a thicker border plus the yellow fill. Material UI defaults to color plus shape for the same reason.

A gradient-masked star has only color to work with, so its empty color has to clear 3:1 on its own. A quick color contrast check on the filled and empty pair takes seconds.

The hit area is where small stars get caught. SC 2.5.8 sets 24 by 24 CSS pixels at Level AA, and a star sized at 1em on a 16 pixel font is only 16 by 16. Padding on the label grows the target without growing the glyph.

Undersized targets still pass if a 24 CSS pixel diameter circle centered on each one does not intersect another target or the circle of another undersized target (W3C).

The thresholds, for reference:

  • 3:1 minimum contrast for the visual information that identifies a control and its states (WCAG 2.2 SC 1.4.11, Level AA)
  • 24 by 24 CSS pixels minimum target size (SC 2.5.8, Level AA)
  • 44 by 44 CSS pixels enhanced target size (SC 2.5.5, Level AAA)
  • 1.2:1 contrast of #FFF000 yellow on white, listed by W3C as a failing star rating

How to pair a CSS star rating with AggregateRating markup

CSS stars never reach search results by themselves. Google reads AggregateRating structured data, which needs a ratingValue plus a ratingCount or reviewCount, nested in a supported type such as Product (Google Search Central, documentation updated 8 September 2026).

The name of the item being rated is required too. bestRating and worstRating are only recommended, and Google assumes 5 and 1 when they are left out. Decimals take a dot, never a comma, so 4.4 and not 4,4.

CSS takes a dot as well, so one number can feed both the –rating custom property and the JSON-LD ratingValue. In Microdata and RDFa, a content attribute lets the visible text read 4,4 while the markup carries 4.4.

Google’s own Product example pairs a ratingValue of 4.4 with a ratingCount of 89. The matching CSS fill is 88%.

In a typical product card design, the stars, the average and the count sit together. Google requires that users can see the aggregate rating on the page, so print the same numbers the markup carries.

The markup has limits, and a few of them catch people off guard:

  • Only supported types qualify. Google names Book, Course, Event, LocalBusiness, Movie, Product, Recipe and SoftwareApplication, plus a few others such as Game, Episode and MediaObject. Article is not among them, so a rating widget on a blog post earns no stars
  • Ratings collected on other websites cannot be aggregated into yours
  • LocalBusiness and Organization pages are ineligible when the reviewed entity controls the reviews about itself, a guideline Google introduced in September 2019
  • Valid markup carries no guarantee that a rich result appears

When does a CSS star rating stop working?

The limits show up when the vote has to leave the page without a form submit, when the layout flips right-to-left, when half stars are needed from radio inputs, or when the browser forces its own colors. Each one is documented.

A radio group submits through a form or it does not submit. MDN confirms that only checked radios are sent, and a group with nothing selected is left out of the form data entirely.

Registering a vote without leaving the page still takes a script. A plain form post works, at the cost of a full page load.

Half-star input splits each star into two click targets, as Mishka UI’s Rating documentation puts it. With SC 2.5.8 asking for 24 CSS pixels, each half needs 24, so a star has to be 48 pixels wide unless the spacing exception applies.

In a right-to-left layout, MDN notes that row and row-reverse follow the container’s directionality, so a row starts on the right. The row-reverse build then shows its stars in the opposite order, and a gradient written with a physical angle keeps filling from the left.

Decide whether the stars mirror, then match the gradient angle to that choice.

Forced-colors mode is the least obvious one. MDN lists background-image among the properties it rewrites, so any value that is not url-based becomes none. Color, border-color and SVG fill are forced to system colors as well.

Gradient-filled stars lose their fill, while a filled glyph and an outline glyph keep their shape difference. The feature has been available across browsers since September 2022 and is Baseline Widely available, so a small @media (forced-colors: active) rule with system color keywords is a safe patch.

Past these limits, stop adding selectors. Web Awesome’s rating component documents a precision attribute for half stars, a name and value submitted with the form, and readonly and required states (Web Awesome documentation).

The price is a JavaScript dependency. For a five-star review form with full-star votes, a native radio group styled with CSS still beats any div-based widget.

CSS Star Rating FAQ

Can Font Awesome or Bootstrap Icons replace CSS-drawn stars?

Yes. An icon font or SVG icon set supplies the star shape, and CSS still controls size, color and state.

Fractional fills need an overlay or mask on top, and the icons should be hidden from screen readers so the rating label does the talking.

How do I animate stars on hover?

Add a transition to the label, such as a short transform scale or color change, and trigger it on :hover.

Wrap the motion in prefers-reduced-motion: no-preference so people who turned animation off in their system settings do not get it.

Can I build a star rating with Tailwind CSS?

Yes. Utility classes handle size, color and spacing, and the peer-checked variant handles state when the row is reversed.

For natural DOM order, the has- variant does the same job as the :has() selector in plain CSS.

How do I change the number of stars, for example to 10?

Add radio and label pairs until you reach ten, then change the divisor in the fill calculation to match, such as calc(var(–rating) / 10 * 100%).

Set bestRating to 10 in the AggregateRating markup too, because Google assumes 5 when it is missing.

How do I save the selected rating to a server?

Put the radios inside a form with a shared name and a value on each input. On submit, the checked radio is sent as name=value (MDN).

The page reloads unless JavaScript intercepts the submit and sends it with fetch. CSS cannot send data on its own.

Which CSS Star Rating Approach to Ship First

Ship the read-only display first. That means a CSS star rating driven by one custom property, with a text label and AggregateRating markup.

After that comes the radio input, with its focus ring and 24 pixel targets, and last the half-star, right-to-left and forced-colors checks.

Display goes first because the contrast and markup rules already apply to it, and later steps reuse its stars.

The cost is a first release that collects no votes, so scores must arrive from an existing review system. Half-star input raises the bar further, since five stars at 48 pixels each need 240 CSS pixels of row width before any gaps.

The order was checked on 27 October 2026 and changes if votes must save without a page reload, which adds JavaScript or a component at step two.

Run the finished widget through a web accessibility checklist before release.