# NPS Rating Scale

> A 0 to 10 "how likely are you to recommend us" scale where the chosen score turns red, amber or green.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: nps, survey, rating, 0 to 10, feedback, radio, scale
- Live preview: https://copy-css.com/snippets/nps-rating-scale
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<fieldset class="nps-survey">
  <legend>How likely are you to recommend us to a friend?</legend>
  <div class="nps-survey-scale">
    <label><input type="radio" name="nps-survey" value="0">0</label>
    <label><input type="radio" name="nps-survey" value="1">1</label>
    <label><input type="radio" name="nps-survey" value="2">2</label>
    <label><input type="radio" name="nps-survey" value="3">3</label>
    <label><input type="radio" name="nps-survey" value="4">4</label>
    <label><input type="radio" name="nps-survey" value="5">5</label>
    <label><input type="radio" name="nps-survey" value="6">6</label>
    <label><input type="radio" name="nps-survey" value="7">7</label>
    <label><input type="radio" name="nps-survey" value="8">8</label>
    <label><input type="radio" name="nps-survey" value="9" checked>9</label>
    <label><input type="radio" name="nps-survey" value="10">10</label>
  </div>
  <p class="nps-survey-ends"><span>Not likely</span><span>Very likely</span></p>
</fieldset>
```

## CSS

```css
.nps-survey {
  width: 100%;
  min-width: 0;
  max-width: 340px;
  margin: 0;
  padding: 0;
  border: 0;
  color: #0f172a;
  font-family: system-ui, sans-serif;
}

.nps-survey legend {
  margin-bottom: 10px;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
}

.nps-survey-scale {
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  gap: 3px;
}

.nps-survey-scale label {
  position: relative;
  display: grid;
  place-items: center;
  height: 34px;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.nps-survey-scale input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.nps-survey-scale label:hover {
  border-color: #94a3b8;
}

.nps-survey-scale label:nth-child(-n + 7):has(:checked) {
  border-color: #ef4444;
  background: #ef4444;
  color: #fff;
}

.nps-survey-scale label:nth-child(n + 8):nth-child(-n + 9):has(:checked) {
  border-color: #f59e0b;
  background: #f59e0b;
  color: #fff;
}

.nps-survey-scale label:nth-child(n + 10):has(:checked) {
  border-color: #16a34a;
  background: #16a34a;
  color: #fff;
}

.nps-survey-scale label:has(:focus-visible) {
  outline: 2px solid #0f172a;
  outline-offset: 2px;
}

.nps-survey-ends {
  display: flex;
  justify-content: space-between;
  margin: 6px 0 0;
  color: #64748b;
  font-size: 12px;
}
```

## Notes

- This CSS NPS Rating Scale is 77 lines of pure CSS (1.3 KB) with no JavaScript and no dependencies. It uses CSS Grid, Flexbox, the :has() selector and the :checked state (no JavaScript).
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
