CSS NPS Rating Scale
A 0 to 10 "how likely are you to recommend us" scale where the chosen score turns red, amber or green.
<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>
.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;
}
About this CSS NPS Rating Scale
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). It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
- CSS Grid
- Flexbox
- the :has() selectorChrome 105+, Safari 15.4+, Firefox 121+.
- the :checked state (no JavaScript)
- keyboard focus styles
Customize it
The colors in this snippet. Search and replace them to match your brand:
#0f172a#e2e8f0#fff#94a3b8#ef4444#f59e0b#16a34a#64748b
How to use this nps rating scale
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.nps-surveyclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.