Bootstrap 5 Rating Scale 1 to 10
A 1-to-10 rating scale with hover preview, a live score readout and a submit button, built on accessible radio inputs.
<section class="wdw-stage">
<div class="container" style="max-width:720px">
<div class="wdw-card p-4 p-md-5 text-center" id="rater">
<span class="wdw-icon mb-3" aria-hidden="true">
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1L3.2 9.5l6.1-.9L12 3z"/></svg>
</span>
<h1 class="wdw-heading h3 mb-2">How would you rate your experience?</h1>
<p class="wdw-muted mb-4">Choose a score from 1 to 10. Your feedback helps us improve.</p>
<fieldset>
<legend class="visually-hidden">Rating from 1 to 10</legend>
<div class="rate-scale d-flex gap-1 gap-sm-2 justify-content-center" data-scale></div>
</fieldset>
<div class="d-flex justify-content-between small text-body-secondary mt-2 px-1"><span>Not great</span><span>Excellent</span></div>
<div class="rate-readout mt-4" role="status" aria-live="polite">
<span class="display-4 fw-bold text-primary lh-1" data-score>–</span><span class="fs-5 text-body-secondary">/10</span>
<p class="fw-semibold mb-0 mt-1 text-body-emphasis" data-word>Tap a number to rate</p>
</div>
<button type="button" class="btn btn-primary rounded-pill px-5 mt-4" data-submit disabled>Submit rating</button>
</div>
</div>
</section>
/* Web Designer Wall library style — shared base for every Bootstrap 5 snippet.
Indigo accent, Plus Jakarta Sans, soft cards, pill buttons. Works in light and dark. */
@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");
:root,
[data-bs-theme="light"] {
--wdw-font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
--bs-body-font-family: var(--wdw-font);
--bs-primary: #4f46e5;
--bs-primary-rgb: 79, 70, 229;
--bs-primary-text-emphasis: #3730a3;
--bs-primary-bg-subtle: #eef2ff;
--bs-primary-border-subtle: #c7d2fe;
--bs-link-color: #4f46e5;
--bs-link-color-rgb: 79, 70, 229;
--bs-link-hover-color: #4338ca;
--bs-link-hover-color-rgb: 67, 56, 202;
--bs-focus-ring-color: rgba(79, 70, 229, 0.25);
--bs-border-radius: 0.75rem;
--bs-border-radius-lg: 1rem;
--bs-border-radius-xl: 1.25rem;
--wdw-radius-card: 1.25rem;
--wdw-shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 16px 40px -16px rgba(16, 24, 40, 0.22);
--wdw-shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px -4px rgba(16, 24, 40, 0.12);
--wdw-stage: #f5f6fb;
}
[data-bs-theme="dark"] {
--bs-primary: #818cf8;
--bs-primary-rgb: 129, 140, 248;
--bs-primary-text-emphasis: #c7d2fe;
--bs-primary-bg-subtle: rgba(129, 140, 248, 0.14);
--bs-primary-border-subtle: rgba(129, 140, 248, 0.35);
--bs-link-color: #a5b4fc;
--bs-link-color-rgb: 165, 180, 252;
--bs-link-hover-color: #c7d2fe;
--bs-link-hover-color-rgb: 199, 210, 254;
--bs-focus-ring-color: rgba(129, 140, 248, 0.35);
--wdw-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -16px rgba(0, 0, 0, 0.7);
--wdw-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px -4px rgba(0, 0, 0, 0.5);
--wdw-stage: #0f1117;
}
body { font-family: var(--wdw-font); -webkit-font-smoothing: antialiased; }
/* Bootstrap compiles its blue into these components; point them at the accent. */
.btn-primary {
--bs-btn-bg: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: #4338ca; --bs-btn-hover-border-color: #4338ca;
--bs-btn-active-bg: #3730a3; --bs-btn-active-border-color: #3730a3;
--bs-btn-disabled-bg: var(--bs-primary); --bs-btn-disabled-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
[data-bs-theme="dark"] .btn-primary { --bs-btn-color: #0f1117; --bs-btn-hover-bg: #a5b4fc; --bs-btn-hover-border-color: #a5b4fc; --bs-btn-hover-color: #0f1117; --bs-btn-active-color: #0f1117; }
.btn-outline-primary {
--bs-btn-color: var(--bs-primary); --bs-btn-border-color: var(--bs-primary);
--bs-btn-hover-bg: var(--bs-primary); --bs-btn-hover-border-color: var(--bs-primary);
--bs-btn-active-bg: var(--bs-primary); --bs-btn-active-border-color: var(--bs-primary);
--bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}
.btn { --bs-btn-font-weight: 600; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; }
.btn-sm { min-height: 36px; }
.form-control, .form-select { min-height: 44px; border-radius: .75rem; }
.form-control:focus, .form-select:focus, .form-check-input:focus { border-color: rgba(var(--bs-primary-rgb), .6); box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.form-check-input:checked { background-color: var(--bs-primary); border-color: var(--bs-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--bs-primary); }
.nav { --bs-nav-link-color: var(--bs-secondary-color); --bs-nav-link-hover-color: var(--bs-emphasis-color); }
.pagination { --bs-pagination-active-bg: var(--bs-primary); --bs-pagination-active-border-color: var(--bs-primary); --bs-pagination-color: var(--bs-body-color); --bs-pagination-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.progress, .progress-stacked { --bs-progress-bar-bg: var(--bs-primary); }
.list-group { --bs-list-group-active-bg: var(--bs-primary); --bs-list-group-active-border-color: var(--bs-primary); }
.dropdown-menu { --bs-dropdown-link-active-bg: var(--bs-primary); border-radius: .875rem; box-shadow: var(--wdw-shadow-sm); }
.accordion { --bs-accordion-active-bg: var(--bs-primary-bg-subtle); --bs-accordion-active-color: var(--bs-primary-text-emphasis); --bs-accordion-btn-focus-box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
.badge { font-weight: 600; }
/* Library building blocks — use these instead of re-inventing them per snippet. */
.wdw-stage { min-height: 100vh; display: flex; align-items: center; background: var(--wdw-stage); padding-block: 3rem; }
.wdw-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: var(--wdw-radius-card); box-shadow: var(--wdw-shadow); }
.wdw-card-sm { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color-translucent); border-radius: 1rem; box-shadow: var(--wdw-shadow-sm); }
.wdw-aurora { position: relative; color: #fff; background: radial-gradient(60% 55% at 100% 0, #818cf8 0, transparent 70%), radial-gradient(65% 60% at 0 100%, #ec4899 0, transparent 65%), #1e1b4b; }
.wdw-eyebrow { display: inline-block; font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--bs-primary); }
.wdw-heading { font-weight: 800; letter-spacing: -.02em; color: var(--bs-emphasis-color); }
.wdw-muted { color: var(--bs-secondary-color); }
.wdw-icon { width: 2.75rem; height: 2.75rem; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: .875rem; background: var(--bs-primary-bg-subtle); color: var(--bs-primary); }
/* Component */
#rater .rate-scale .rate { flex: 1 1 0; max-width: 56px; }
#rater .rate-scale label { width: 100%; min-height: 56px; padding: 0; border-radius: .875rem; font-weight: 700; background: var(--bs-tertiary-bg); border: 1px solid var(--bs-border-color); color: var(--bs-secondary-color); cursor: pointer; transition: background-color .15s, color .15s, transform .15s, border-color .15s; }
#rater .rate-scale label.on { background: var(--bs-primary-bg-subtle); border-color: var(--bs-primary-border-subtle); color: var(--bs-primary-text-emphasis); }
#rater .rate-scale input:checked + label { background: var(--bs-primary); border-color: var(--bs-primary); color: #fff; transform: translateY(-2px); }
[data-bs-theme="dark"] #rater .rate-scale input:checked + label { color: #0f1117; }
#rater .rate-scale input:focus-visible + label { box-shadow: 0 0 0 .25rem var(--bs-focus-ring-color); }
#rater .rate-readout { min-height: 6.5rem; }
@media (max-width: 575.98px) { #rater .rate-scale { flex-wrap: wrap; } #rater .rate-scale .rate { flex: 0 0 calc(20% - .2rem); max-width: none; } #rater .rate-scale label { min-height: 48px; border-radius: .75rem; font-size: 1rem; } }
@media (prefers-reduced-motion: reduce) { #rater .rate-scale label { transition: none; } }
function initRater() {
const root = document.getElementById('rater');
if (!root) return;
const scale = root.querySelector('[data-scale]');
const score = root.querySelector('[data-score]');
const word = root.querySelector('[data-word]');
const submit = root.querySelector('[data-submit]');
const words = ['', 'Very poor', 'Poor', 'Below average', 'Fair', 'Okay', 'Good', 'Very good', 'Great', 'Excellent', 'Outstanding'];
let value = 0;
for (let i = 1; i <= 10; i++) {
const wrap = document.createElement('div');
wrap.className = 'rate';
wrap.innerHTML = '<input type="radio" class="btn-check" name="rating" id="rate' + i + '" value="' + i + '"><label class="btn d-flex" for="rate' + i + '" aria-label="' + i + ' out of 10">' + i + '</label>';
scale.appendChild(wrap);
}
const labels = [...scale.querySelectorAll('label')];
const paint = (n) => labels.forEach((l, i) => l.classList.toggle('on', i < n));
const show = (n) => { score.textContent = n || '–'; word.textContent = words[n] || 'Tap a number to rate'; };
scale.addEventListener('mouseover', (e) => { const l = e.target.closest('label'); if (l) { const n = labels.indexOf(l) + 1; paint(n); show(n); } });
scale.addEventListener('mouseleave', () => { paint(value); show(value); });
scale.addEventListener('change', (e) => { value = Number(e.target.value); paint(value); show(value); submit.disabled = false; });
const initial = scale.querySelector('#rate8');
initial.checked = true;
initial.dispatchEvent(new Event('change', { bubbles: true }));
submit.addEventListener('click', () => { word.textContent = 'Thanks! You rated us ' + value + '/10.'; submit.disabled = true; });
}
initRater();
Built on Bootstrap 5.3.8 with plain JavaScript — no jQuery. Supports light and dark mode via data-bs-theme.