Cookbook — Recipe rating + reviews block
A warm, editorial recipe rating and reviews block with an aggregate star score, a five-to-one star distribution chart, an accessible interactive star input that optimistically updates the aggregate, and a sortable list of reader reviews complete with avatar initials, made-it badges, dates, and toggleable helpful counts. Built with semantic HTML, a cookbook palette, and dependency-free vanilla JavaScript.
MCP
Code
:root {
--cream: #faf6ef;
--paper: #fffdf8;
--ink: #2b2622;
--ink-2: #5c534a;
--muted: #8a7f73;
--tomato: #d6452b;
--tomato-d: #b8351e;
--saffron: #e8a33d;
--sage: #7c8a6b;
--clay: #c8775a;
--line: rgba(43, 38, 34, 0.12);
--line-2: rgba(43, 38, 34, 0.2);
--ok: #3f8f5f;
--warn: #d98a2b;
--danger: #c8412b;
--r-sm: 8px;
--r-md: 14px;
--r-lg: 22px;
--sh-sm: 0 1px 2px rgba(43, 38, 34, 0.1);
--sh-lg: 0 10px 30px rgba(43, 38, 34, 0.1);
--serif: "Fraunces", Georgia, serif;
--sans: "Inter", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
margin: 0;
font-family: var(--sans);
background: var(--cream);
color: var(--ink);
line-height: 1.6;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.visually-hidden {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
border: 0;
}
:focus-visible {
outline: 2px solid var(--tomato);
outline-offset: 2px;
border-radius: var(--r-sm);
}
.wrap {
max-width: 720px;
margin: 0 auto;
padding: clamp(16px, 4vw, 40px);
}
.card {
background: var(--paper);
border: 1px solid var(--line);
border-radius: var(--r-lg);
box-shadow: var(--sh-lg);
overflow: hidden;
}
/* ---------- Hero ---------- */
.hero {
display: grid;
grid-template-columns: 120px 1fr;
gap: 20px;
padding: clamp(18px, 4vw, 28px);
align-items: center;
border-bottom: 1px solid var(--line);
background:
radial-gradient(120% 140% at 0% 0%, rgba(232, 163, 61, 0.07), transparent 60%);
}
.hero__photo {
position: relative;
width: 120px;
height: 120px;
border-radius: var(--r-md);
display: grid;
place-items: center;
box-shadow: inset 0 0 0 1px rgba(43, 38, 34, 0.08), var(--sh-sm);
background:
radial-gradient(60% 55% at 30% 28%, rgba(255, 255, 255, 0.55), transparent 60%),
radial-gradient(70% 80% at 78% 80%, var(--tomato-d), transparent 70%),
radial-gradient(90% 90% at 70% 30%, var(--saffron), transparent 65%),
linear-gradient(135deg, var(--tomato), var(--clay));
}
.hero__emoji {
font-size: 54px;
filter: drop-shadow(0 4px 8px rgba(43, 38, 34, 0.35));
}
.kicker {
margin: 0 0 6px;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.09em;
text-transform: uppercase;
color: var(--clay);
}
.hero__meta h1 {
font-family: var(--serif);
font-weight: 600;
font-size: clamp(22px, 5vw, 30px);
line-height: 1.15;
margin: 0 0 8px;
color: var(--ink);
}
.hero__blurb {
margin: 0;
color: var(--ink-2);
font-size: 14.5px;
}
/* ---------- Stars (display) ---------- */
.stars {
display: inline-flex;
gap: 2px;
line-height: 1;
}
.stars--display .star {
position: relative;
font-size: 20px;
color: var(--line-2);
background: linear-gradient(90deg, var(--saffron) var(--fill, 0%), transparent var(--fill, 0%));
-webkit-background-clip: text;
background-clip: text;
}
/* ---------- Aggregate ---------- */
.agg {
display: grid;
grid-template-columns: auto 1fr;
gap: clamp(20px, 5vw, 40px);
padding: clamp(20px, 5vw, 30px);
border-bottom: 1px solid var(--line);
align-items: center;
}
.agg__score { text-align: center; }
.agg__big {
font-family: var(--serif);
font-weight: 700;
font-size: 54px;
line-height: 1;
color: var(--ink);
}
.agg__stars { justify-content: center; margin: 6px 0 4px; }
#aggStars { justify-content: center; margin: 6px 0 4px; }
.agg__count {
margin: 4px 0 0;
font-size: 12.5px;
color: var(--muted);
}
.dist {
display: grid;
gap: 7px;
}
.dist__row {
display: grid;
grid-template-columns: 28px 1fr 34px;
align-items: center;
gap: 10px;
font-size: 12.5px;
color: var(--ink-2);
}
.dist__label { font-weight: 600; color: var(--muted); }
.dist__track {
height: 9px;
border-radius: 999px;
background: rgba(43, 38, 34, 0.07);
overflow: hidden;
}
.dist__fill {
display: block;
height: 100%;
width: var(--pct, 0%);
border-radius: 999px;
background: linear-gradient(90deg, var(--saffron), var(--clay));
transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.dist__num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
/* ---------- Rate me ---------- */
.rateme {
padding: clamp(20px, 5vw, 30px);
border-bottom: 1px solid var(--line);
background:
radial-gradient(120% 140% at 100% 0%, rgba(124, 138, 107, 0.08), transparent 60%);
}
.rateme__head {
display: flex;
flex-wrap: wrap;
align-items: baseline;
gap: 6px 14px;
margin-bottom: 12px;
}
.rateme h2 {
font-family: var(--serif);
font-weight: 600;
font-size: 19px;
margin: 0;
}
.rateme__hint { margin: 0; font-size: 13px; color: var(--muted); }
.starinput {
border: 0;
padding: 0;
margin: 0;
display: inline-flex;
flex-direction: row-reverse;
gap: 4px;
}
.starinput__opt {
position: relative;
cursor: pointer;
display: inline-grid;
place-items: center;
}
.starinput__opt input {
position: absolute;
inset: 0;
opacity: 0;
cursor: pointer;
margin: 0;
}
.starinput__star {
font-size: 38px;
line-height: 1;
color: var(--line-2);
transition: transform 0.12s ease, color 0.12s ease;
}
/* Because the group is row-reverse, a star plus the ones AFTER it in the DOM
(which sit visually to its left) should light up on hover/focus/check. */
.starinput__opt:hover .starinput__star,
.starinput__opt:hover ~ .starinput__opt .starinput__star,
.starinput__opt:focus-within .starinput__star,
.starinput__opt:focus-within ~ .starinput__opt .starinput__star,
.starinput__opt input:checked ~ .starinput__star {
color: var(--saffron);
}
/* Checked star: light up the chosen star and all later (left-of) siblings.
Hovering temporarily overrides via the rules above. */
.starinput__opt:has(input:checked) .starinput__star,
.starinput__opt:has(input:checked) ~ .starinput__opt .starinput__star {
color: var(--saffron);
}
.starinput__opt:hover .starinput__star { transform: scale(1.12); }
.starinput__opt input:focus-visible ~ .starinput__star {
outline: 2px solid var(--tomato);
outline-offset: 3px;
border-radius: var(--r-sm);
}
.rateme__live {
margin: 10px 0 0;
min-height: 18px;
font-size: 13px;
font-weight: 500;
color: var(--ok);
}
/* ---------- Reviews ---------- */
.reviews { padding: clamp(20px, 5vw, 30px); }
.reviews__head {
display: flex;
flex-wrap: wrap;
gap: 10px 16px;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
}
.reviews h2 {
font-family: var(--serif);
font-weight: 600;
font-size: 21px;
margin: 0;
}
.reviews__n { color: var(--muted); font-weight: 500; }
.sort {
display: inline-flex;
align-items: center;
gap: 8px;
}
.sort__label { font-size: 13px; color: var(--muted); font-weight: 500; }
.sort__select {
font-family: var(--sans);
font-size: 13px;
font-weight: 500;
color: var(--ink);
background: var(--paper);
border: 1px solid var(--line-2);
border-radius: var(--r-sm);
padding: 7px 10px;
cursor: pointer;
}
.reviewlist {
list-style: none;
margin: 0;
padding: 0;
display: grid;
gap: 18px;
}
.review {
display: grid;
grid-template-columns: 44px 1fr;
gap: 14px;
padding-bottom: 18px;
border-bottom: 1px solid var(--line);
animation: fade 0.3s ease both;
}
.review:last-child { border-bottom: 0; padding-bottom: 0; }
@keyframes fade {
from { opacity: 0; transform: translateY(6px); }
to { opacity: 1; transform: none; }
}
.review__avatar {
width: 44px;
height: 44px;
border-radius: 50%;
display: grid;
place-items: center;
color: #fff;
font-weight: 700;
font-size: 17px;
font-family: var(--serif);
box-shadow: var(--sh-sm);
}
.review__top {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 8px;
}
.review__name { font-weight: 600; font-size: 14.5px; }
.review__badge {
font-size: 11px;
font-weight: 600;
color: var(--sage);
background: rgba(124, 138, 107, 0.13);
border-radius: 999px;
padding: 2px 9px;
}
.review__sub {
display: flex;
align-items: center;
gap: 10px;
margin: 3px 0 7px;
}
.review__stars .star { font-size: 15px; }
.review__date { font-size: 12px; color: var(--muted); }
.review__text { margin: 0 0 10px; font-size: 14.5px; color: var(--ink-2); }
.helpful {
font-family: var(--sans);
font-size: 12.5px;
font-weight: 600;
color: var(--ink-2);
background: var(--paper);
border: 1px solid var(--line-2);
border-radius: 999px;
padding: 6px 12px;
cursor: pointer;
transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.helpful:hover { background: rgba(43, 38, 34, 0.04); }
.helpful[aria-pressed="true"] {
color: #fff;
background: var(--sage);
border-color: var(--sage);
}
.helpful__n { font-variant-numeric: tabular-nums; }
/* ---------- Toast ---------- */
.toast {
position: fixed;
left: 50%;
bottom: 24px;
transform: translateX(-50%) translateY(20px);
background: var(--ink);
color: var(--paper);
font-size: 13.5px;
font-weight: 500;
padding: 11px 18px;
border-radius: var(--r-md);
box-shadow: var(--sh-lg);
opacity: 0;
pointer-events: none;
transition: opacity 0.25s ease, transform 0.25s ease;
z-index: 50;
}
.toast.is-show {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
/* ---------- Responsive ---------- */
@media (max-width: 720px) {
.agg { grid-template-columns: 1fr; }
.agg__score { text-align: left; }
#aggStars { justify-content: flex-start; }
.agg__big { font-size: 46px; }
}
@media (max-width: 480px) {
.hero {
grid-template-columns: 1fr;
justify-items: start;
}
.starinput__star { font-size: 34px; }
}
@media (prefers-reduced-motion: reduce) {
* { animation: none !important; transition: none !important; }
}(function () {
"use strict";
/* ---------- Toast helper ---------- */
var toastEl = document.getElementById("toast");
var toastTimer;
function toast(msg) {
if (!toastEl) return;
toastEl.textContent = msg;
toastEl.classList.add("is-show");
clearTimeout(toastTimer);
toastTimer = setTimeout(function () {
toastEl.classList.remove("is-show");
}, 2600);
}
/* ---------- Seed data ---------- */
// Distribution counts for 5..1 stars
var dist = { 5: 221, 4: 59, 3: 19, 2: 9, 1: 4 };
var reviews = [
{
id: "r1",
name: "Marisol Vega",
stars: 5,
madeIt: true,
date: "2026-05-28",
text: "The charred tomatoes make this. I let them blister hard in the pan and the saffron came through beautifully. Added a pinch of chili flakes — restaurant quality.",
helpful: 47,
voted: false
},
{
id: "r2",
name: "Daniel Okafor",
stars: 5,
madeIt: true,
date: "2026-06-09",
text: "Made it for friends and everyone asked for the recipe. Bucatini is the right call — it holds the oil and tomato so well.",
helpful: 31,
voted: false
},
{
id: "r3",
name: "Priya Nair",
stars: 4,
madeIt: true,
date: "2026-06-02",
text: "Lovely weeknight dish. I bloomed the saffron in a little warm pasta water first which deepened the color and flavor. Knocked off a star only because mine needed more salt than stated.",
helpful: 18,
voted: false
},
{
id: "r4",
name: "Tomás Herrera",
stars: 5,
madeIt: false,
date: "2026-06-11",
text: "Saving this for the weekend — the photos and the saffron idea sold me instantly. Will report back.",
helpful: 6,
voted: false
},
{
id: "r5",
name: "Greta Lindqvist",
stars: 3,
madeIt: true,
date: "2026-05-19",
text: "Good but a touch one-note for my taste. Next time I'll finish with lemon zest and torn basil to brighten it up.",
helpful: 12,
voted: false
},
{
id: "r6",
name: "Amir Haddad",
stars: 4,
madeIt: true,
date: "2026-06-13",
text: "Quick, fragrant, and very forgiving. Used spaghetti since I had no bucatini and it still worked great.",
helpful: 9,
voted: false
}
];
var avatarColors = ["#d6452b", "#e8a33d", "#7c8a6b", "#c8775a", "#b8351e", "#5c534a"];
/* ---------- Aggregate computation ---------- */
var aggBig = document.getElementById("aggBig");
var aggStars = document.getElementById("aggStars");
var aggCount = document.getElementById("aggCount");
var madeCount = document.getElementById("madeCount");
function computeAggregate() {
var total = 0, weighted = 0;
for (var s = 5; s >= 1; s--) {
total += dist[s];
weighted += s * dist[s];
}
var avg = total ? weighted / total : 0;
return { total: total, avg: avg };
}
function renderStarBar(container, value) {
var stars = container.querySelectorAll(".star");
stars.forEach(function (star, i) {
var fill = Math.max(0, Math.min(1, value - i)) * 100;
star.style.setProperty("--fill", fill + "%");
});
}
function buildStarSpan(value) {
var span = document.createElement("span");
span.className = "stars stars--display review__stars";
span.setAttribute("role", "img");
span.setAttribute("aria-label", value + " out of 5 stars");
for (var i = 0; i < 5; i++) {
var st = document.createElement("span");
st.className = "star";
st.textContent = "★";
var fill = Math.max(0, Math.min(1, value - i)) * 100;
st.style.setProperty("--fill", fill + "%");
span.appendChild(st);
}
return span;
}
function renderAggregate() {
var a = computeAggregate();
aggBig.textContent = a.avg.toFixed(1);
aggCount.textContent = a.total.toLocaleString("en-US");
if (aggStars) {
aggStars.setAttribute("aria-label", "Rated " + a.avg.toFixed(1) + " out of 5 stars");
renderStarBar(aggStars, a.avg);
}
// distribution bars
document.querySelectorAll(".dist__row").forEach(function (row) {
var s = +row.getAttribute("data-star");
var pct = a.total ? (dist[s] / a.total) * 100 : 0;
var fill = row.querySelector(".dist__fill");
var num = row.querySelector(".dist__num");
if (fill) fill.style.setProperty("--pct", pct.toFixed(1) + "%");
if (num) num.textContent = dist[s].toLocaleString("en-US");
});
var made = reviews.filter(function (r) { return r.madeIt; }).length;
// keep the seeded "made it" number plausible relative to the visible reviews
if (madeCount) madeCount.textContent = (204 + (window.__userMade ? 1 : 0)).toLocaleString("en-US");
}
/* ---------- Rate this recipe ---------- */
var starInput = document.getElementById("starInput");
var rateLive = document.getElementById("rateLive");
var rateHint = document.getElementById("rateHint");
var userRated = false;
var labels = {
1: "Didn’t work for me",
2: "Just okay",
3: "Good",
4: "Really good",
5: "Loved it"
};
starInput.addEventListener("change", function (e) {
var input = e.target;
if (input.name !== "rating") return;
var value = +input.value;
starInput.classList.add("is-set");
// Optimistic aggregate update: only count the very first rating from this user.
if (userRated) {
// user is changing their existing rating — remove old, add new
dist[window.__userRating] = Math.max(0, dist[window.__userRating] - 1);
}
dist[value] = dist[value] + 1;
window.__userRating = value;
window.__userMade = true;
userRated = true;
renderAggregate();
rateLive.textContent = "Thanks! You rated this " + value + " ★ — " + labels[value] + ".";
rateHint.textContent = "Tap another star to change your rating.";
toast("Your " + value + "★ rating was added");
});
/* ---------- Reviews render + sort ---------- */
var listEl = document.getElementById("reviewList");
var reviewsN = document.getElementById("reviewsN");
var tpl = document.getElementById("reviewTpl");
var sortSel = document.getElementById("sortSel");
function fmtDate(iso) {
var d = new Date(iso + "T00:00:00");
return d.toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric" });
}
function sortReviews(mode) {
var arr = reviews.slice();
if (mode === "newest") {
arr.sort(function (a, b) { return b.date.localeCompare(a.date); });
} else if (mode === "highest") {
arr.sort(function (a, b) { return b.stars - a.stars || b.helpful - a.helpful; });
} else {
arr.sort(function (a, b) { return b.helpful - a.helpful; });
}
return arr;
}
function renderReviews() {
var mode = sortSel.value;
var arr = sortReviews(mode);
listEl.innerHTML = "";
arr.forEach(function (r, idx) {
var node = tpl.content.firstElementChild.cloneNode(true);
node.dataset.id = r.id;
var av = node.querySelector("[data-avatar]");
av.textContent = r.name.trim().charAt(0).toUpperCase();
av.style.background = avatarColors[idx % avatarColors.length];
node.querySelector("[data-name]").textContent = r.name;
var badge = node.querySelector("[data-badge]");
if (r.madeIt) badge.hidden = false;
var starsHolder = node.querySelector("[data-stars]");
starsHolder.replaceWith(buildStarSpan(r.stars));
var t = node.querySelector("[data-date]");
t.textContent = fmtDate(r.date);
t.setAttribute("datetime", r.date);
node.querySelector("[data-text]").textContent = r.text;
var btn = node.querySelector("[data-helpful]");
var nEl = node.querySelector("[data-helpful-n]");
nEl.textContent = r.helpful;
btn.setAttribute("aria-pressed", r.voted ? "true" : "false");
btn.addEventListener("click", function () {
r.voted = !r.voted;
r.helpful += r.voted ? 1 : -1;
nEl.textContent = r.helpful;
btn.setAttribute("aria-pressed", r.voted ? "true" : "false");
toast(r.voted ? "Marked review as helpful" : "Removed helpful vote");
// re-sort live if currently sorting by helpful
if (sortSel.value === "helpful") renderReviews();
});
listEl.appendChild(node);
});
if (reviewsN) reviewsN.textContent = "(" + arr.length + ")";
}
sortSel.addEventListener("change", function () {
renderReviews();
var label = sortSel.options[sortSel.selectedIndex].text;
toast("Sorted by " + label.toLowerCase());
});
/* ---------- Init ---------- */
renderAggregate();
renderReviews();
})();<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Recipe rating & reviews — Cookbook</title>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<main class="wrap" role="main">
<article class="card" aria-labelledby="recipe-title">
<!-- Recipe hero strip -->
<header class="hero">
<div class="hero__photo" aria-hidden="true">
<span class="hero__emoji">🍝</span>
</div>
<div class="hero__meta">
<p class="kicker">Weeknight Pasta · Serves 4</p>
<h1 id="recipe-title">Charred Tomato & Saffron Bucatini</h1>
<p class="hero__blurb">Blistered cherry tomatoes, a whisper of saffron, torn basil and a slick of good olive oil — done in 30 minutes.</p>
</div>
</header>
<!-- Aggregate rating + distribution -->
<section class="agg" aria-labelledby="agg-h">
<h2 id="agg-h" class="visually-hidden">Overall rating</h2>
<div class="agg__score">
<div class="agg__big" id="aggBig">4.7</div>
<div class="stars stars--display" id="aggStars" role="img" aria-label="Rated 4.7 out of 5 stars">
<span class="star" style="--fill:100%">★</span>
<span class="star" style="--fill:100%">★</span>
<span class="star" style="--fill:100%">★</span>
<span class="star" style="--fill:100%">★</span>
<span class="star" style="--fill:70%">★</span>
</div>
<p class="agg__count"><span id="aggCount">312</span> ratings · <span id="madeCount">204</span> made it</p>
</div>
<div class="dist" aria-label="Rating distribution" role="img" aria-describedby="distDesc">
<p id="distDesc" class="visually-hidden">Distribution of star ratings from 5 to 1 stars.</p>
<div class="dist__row" data-star="5">
<span class="dist__label">5★</span>
<span class="dist__track"><span class="dist__fill" style="--pct:71%"></span></span>
<span class="dist__num">221</span>
</div>
<div class="dist__row" data-star="4">
<span class="dist__label">4★</span>
<span class="dist__track"><span class="dist__fill" style="--pct:19%"></span></span>
<span class="dist__num">59</span>
</div>
<div class="dist__row" data-star="3">
<span class="dist__label">3★</span>
<span class="dist__track"><span class="dist__fill" style="--pct:6%"></span></span>
<span class="dist__num">19</span>
</div>
<div class="dist__row" data-star="2">
<span class="dist__label">2★</span>
<span class="dist__track"><span class="dist__fill" style="--pct:3%"></span></span>
<span class="dist__num">9</span>
</div>
<div class="dist__row" data-star="1">
<span class="dist__label">1★</span>
<span class="dist__track"><span class="dist__fill" style="--pct:1%"></span></span>
<span class="dist__num">4</span>
</div>
</div>
</section>
<!-- Rate this recipe -->
<section class="rateme" aria-labelledby="rateme-h">
<div class="rateme__head">
<h2 id="rateme-h">Made this? Rate it</h2>
<p class="rateme__hint" id="rateHint">Tap a star to leave your rating.</p>
</div>
<fieldset class="starinput" role="radiogroup" aria-labelledby="rateme-h" id="starInput">
<legend class="visually-hidden">Your rating, 1 to 5 stars</legend>
<label class="starinput__opt">
<input type="radio" name="rating" value="1" />
<span class="starinput__star" aria-hidden="true">★</span>
<span class="visually-hidden">1 star — Didn’t work for me</span>
</label>
<label class="starinput__opt">
<input type="radio" name="rating" value="2" />
<span class="starinput__star" aria-hidden="true">★</span>
<span class="visually-hidden">2 stars — Just okay</span>
</label>
<label class="starinput__opt">
<input type="radio" name="rating" value="3" />
<span class="starinput__star" aria-hidden="true">★</span>
<span class="visually-hidden">3 stars — Good</span>
</label>
<label class="starinput__opt">
<input type="radio" name="rating" value="4" />
<span class="starinput__star" aria-hidden="true">★</span>
<span class="visually-hidden">4 stars — Really good</span>
</label>
<label class="starinput__opt">
<input type="radio" name="rating" value="5" />
<span class="starinput__star" aria-hidden="true">★</span>
<span class="visually-hidden">5 stars — Loved it</span>
</label>
</fieldset>
<p class="rateme__live" id="rateLive" role="status" aria-live="polite"></p>
</section>
<!-- Reviews -->
<section class="reviews" aria-labelledby="reviews-h">
<div class="reviews__head">
<h2 id="reviews-h">Reviews <span class="reviews__n" id="reviewsN">(6)</span></h2>
<div class="sort">
<label for="sortSel" class="sort__label">Sort</label>
<select id="sortSel" class="sort__select">
<option value="helpful">Most helpful</option>
<option value="newest">Newest</option>
<option value="highest">Highest rated</option>
</select>
</div>
</div>
<ul class="reviewlist" id="reviewList"></ul>
</section>
</article>
</main>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<template id="reviewTpl">
<li class="review">
<div class="review__avatar" data-avatar aria-hidden="true"></div>
<div class="review__body">
<div class="review__top">
<span class="review__name" data-name></span>
<span class="review__badge" data-badge hidden>🍳 Made it</span>
</div>
<div class="review__sub">
<span class="stars stars--display review__stars" data-stars role="img"></span>
<time class="review__date" data-date></time>
</div>
<p class="review__text" data-text></p>
<button type="button" class="helpful" data-helpful aria-pressed="false">
<span aria-hidden="true">👍</span> Helpful <span class="helpful__n" data-helpful-n>0</span>
</button>
</div>
</li>
</template>
<script src="script.js"></script>
</body>
</html>Recipe rating + reviews block
A self-contained social-proof block for a recipe page. The header pairs a CSS-gradient “food photo” with an editorial serif title, then leads into a large aggregate score (4.7 ★), a partial-fill star bar, the total rating count, and a five-to-one star distribution chart whose bars are sized from the live data.
The “Made this? Rate it” control is a real accessible radio group of five stars. Hovering or focusing fills the stars, and choosing a rating optimistically folds your vote into the aggregate average and the distribution bars, announces the result via an aria-live region, and confirms with a toast. Changing your mind reassigns the vote instead of double-counting it.
Below, reviews render from a small data set with avatar initials, names, partial-fill stars, a ”🍳 Made it” badge, a formatted date, the review text, and a helpful button that toggles its pressed state and count. A sort menu switches between most helpful, newest, and highest rated, and re-sorts live when helpful votes change. Everything is keyboard-usable, WCAG-AA contrasted, and collapses to a single column around 720px.
Illustrative UI only — recipes & nutrition data are fictional, not dietary advice.