You built a star widget. The stars look right, they light up when you click, and then you press Send and the server, or the Network tab in your browser's developer tools (open them with F12), or the console shows no rating at all. Or worse, the Send button does nothing and gives you no reason. If you have searched "star rating required radio form won't submit" or "how to submit jquery star rating", this is the page I wish you had landed on. By the end you'll have a five-star rating built from real radio buttons with no JavaScript, and you'll know why it submits.
Here is the idea that fixes it, and it transfers to every custom control you will ever build: the real input holds the value, and the label is only the picture. A form submits what the inputs hold. It has never once submitted what the screen shows.
The widget that looks right and sends nothing
The version an AI tool will often hand you is a row of clickable spans or divs (generic page boxes) with a click handler, a bit of JavaScript that runs on each click, that paints the first few gold. I built the bare shape of that, three spans inside a form, clicked the third and pressed Send in headless Chromium 141.0.7390.37 (a browser run without a window, driven by a script). The address bar ended in this:
stars.html?
Nothing after the question mark. However many stars you paint gold, there's zero data in the request. A span is not a form control, so the form walked right past it.
The second version is subtler. Someone swaps in real radio buttons, hides them with display:none (a CSS rule that removes an element from the page entirely) so only the stars show, and marks the group required, so the browser won't submit until one is picked. I ran that too. Clicking Send with no rating changed nothing on screen, and the console printed this:
An invalid form control with name='rating' is not focusable.
The browser wanted to point at the empty required field and say "pick one". It could not, because a hidden input can't take focus, meaning the keyboard can't land on it. So the form refuses to submit and the reader sees nothing happen. Keyboard users have the same wall for the same reason: you can't Tab to something that isn't there.
Both failures have one cause. The picture and the value were separated, and the picture won.
What you need
A text editor and a browser. The whole widget is one HTML file.
The concept: radio inputs and :has()
A radio input is the round button you've seen on forms, one of a group sharing the same name, where picking one unpicks the others. Here it is <input type="radio">. The browser tracks which one is checked, submits the name with the checked one's value, and handles arrow keys, Tab and the required check for free.
:has() is a CSS selector, a pattern that picks which elements to style, and it matches an element based on what is inside it or after it. 'label:has(~ input:checked)' reads as: a label that has, somewhere after it among its siblings, a checked input. Siblings are elements at the same level, and that '~' means: any later one. Before :has() existed, CSS could only look from the parent down or from an element forward. Now an element can react to something that comes after it.
Walkthrough: build the star rating
Five radios, each with a label. The radios stay in the page but go invisible by shrinking and fading, not by display:none, so they keep focus and keep the required check alive. This is the whole file:
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><title>Rate it</title>
<style>
body { font-family: system-ui, sans-serif; padding: 2rem; }
.stars { display: inline-flex; border: 0; padding: 0; margin: 0; }
.stars legend { padding: 0; margin-bottom: .5rem; }
.stars input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.stars label { font-size: 2.5rem; line-height: 1; color: #bbb; cursor: pointer; }
.stars label:has(~ input:checked),
.stars input:checked + label { color: gold; }
.stars:has(label:hover) label:not(:hover, :has(~ label:hover)) { color: #bbb; }
.stars label:has(~ label:hover),
.stars label:hover { color: gold; }
.stars input:focus-visible + label { outline: 3px solid royalblue; outline-offset: 2px; }
</style></head><body>
<form method="get" action="">
<fieldset class="stars">
<legend>How was it?</legend>
<input type="radio" name="rating" id="s1" value="1" required><label for="s1" title="1 star">★</label>
<input type="radio" name="rating" id="s2" value="2"><label for="s2" title="2 stars">★</label>
<input type="radio" name="rating" id="s3" value="3"><label for="s3" title="3 stars">★</label>
<input type="radio" name="rating" id="s4" value="4"><label for="s4" title="4 stars">★</label>
<input type="radio" name="rating" id="s5" value="5"><label for="s5" title="5 stars">★</label>
</fieldset>
<p><button>Send</button></p>
</form></body></html>
Save it as stars.html in an empty folder and double-click it to open it in your browser. Click the third star, press Send, and look at the address bar. In my run it read:
stars.html?rating=3
That is the value the form sent, and it is the number you wanted. On screen, in Chromium 141.0.7390.37, the same click gave three gold stars and two grey ones.
I'm calling this one seen, not measured. The fill is colour, so I read the computed colour (the final colour the browser works out) of each label: gold on 1, 2 and 3, grey on 4 and 5. I only ran it in that one browser, so I'm not claiming anything about the others. If you try it elsewhere, you're the test. One caution on reach: ':has()' is broadly supported now, but check MDN's ':has()' page (MDN is a widely used web documentation site) against the browsers your readers actually use before you rely on it — and know that the hover preview, the forgiving ':not(:hover, :has(~ label:hover))' line, is the part most likely to fall silent in an engine that doesn't support it, while the fill and the submitted value keep working.
Show the code
<style>
.box { position: relative; border: 1px solid #ccc; border-radius: 8px; padding: 12px; margin: 0 0 12px; }
.box h3 { margin: 0 0 6px; font-size: 16px; }
.fake span { font-size: 2.5rem; line-height: 1; color: #bbb; cursor: pointer; }
.fake span.on { color: gold; }
.stars { display: inline-flex; border: 0; padding: 0; margin: 0; }
.stars legend { padding: 0; margin-bottom: .5rem; }
.stars input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.stars label { font-size: 2.5rem; line-height: 1; color: #bbb; cursor: pointer; }
.stars label:has(~ input:checked),
.stars input:checked + label { color: gold; }
.stars:has(label:hover) label:not(:hover, :has(~ label:hover)) { color: #bbb; }
.stars label:has(~ label:hover),
.stars label:hover { color: gold; }
.stars input:focus-visible + label { outline: 3px solid royalblue; outline-offset: 2px; }
button { min-height: 40px; padding: 0 16px; font: inherit; border: 1px solid #888; border-radius: 8px; background: #f2f2f2; cursor: pointer; }
.out { font-family: monospace; font-size: 15px; margin: 8px 0 0; word-break: break-all; }
</style>
<p>Click the third star in each row, then press each Send. The last line shows what the address bar would end in.</p>
<form class="box" id="f1">
<h3>Spans painted gold by JavaScript</h3>
<div class="fake" id="fake"><span data-n="1">★</span><span data-n="2">★</span><span data-n="3">★</span><span data-n="4">★</span><span data-n="5">★</span></div>
<p><button>Send</button></p>
<p class="out" id="o1">Address bar: (not sent yet)</p>
</form>
<form class="box" id="f2">
<h3>Real radio buttons, styled with :has()</h3>
<fieldset class="stars">
<legend>How was it?</legend>
<input type="radio" name="rating" id="s1" value="1" required><label for="s1" title="1 star">★</label>
<input type="radio" name="rating" id="s2" value="2"><label for="s2" title="2 stars">★</label>
<input type="radio" name="rating" id="s3" value="3"><label for="s3" title="3 stars">★</label>
<input type="radio" name="rating" id="s4" value="4"><label for="s4" title="4 stars">★</label>
<input type="radio" name="rating" id="s5" value="5"><label for="s5" title="5 stars">★</label>
</fieldset>
<p><button>Send</button></p>
<p class="out" id="o2">Address bar: (not sent yet)</p>
</form>
<p id="note"></p>
<script>
const fake = document.getElementById('fake');
fake.addEventListener('click', (e) => {
const n = Number(e.target.dataset.n);
if (!n) return;
for (const s of fake.children) s.classList.toggle('on', Number(s.dataset.n) <= n);
});
for (const [form, out] of [['f1', 'o1'], ['f2', 'o2']]) {
const f = document.getElementById(form);
f.addEventListener('submit', (e) => {
e.preventDefault(); // stay on this page; show what the form would send instead
const query = new URLSearchParams(new FormData(f)).toString();
document.getElementById(out).textContent = 'Address bar: stars.html?' + query;
});
}
if (!CSS.supports('selector(:has(a))')) {
document.getElementById('note').textContent = "Your browser doesn't support :has() yet — the article explains the fallback. The radio row still sends its value.";
}
</script>Where it goes wrong: three rules, not one
The line that makes this feel like magic is 'label:has(~ input:checked)'. Every label that has a checked input after it goes gold. Click star 3 and labels 1 and 2 qualify, because the checked radio sits after them. That's the trick, and it quietly falls short.
I removed the second selector and clicked star 3. The result was gold, gold, grey, grey, grey. The star you clicked stayed empty. A label can't have itself after itself, so the one-liner only fills stars before the checked one. That's why the file has the second selector, 'input:checked + label', which fills the clicked star directly.
Then hover. Without a hover rule nothing previews, and if you add a naive one it fights the checked state. With 4 checked I hovered star 2 and the row showed gold, gold, grey, grey, grey, a preview of 2 while 4 was still the answer. Move the mouse away and it snapped back to four. The 'label:not(:hover, :has(~ label:hover))' line is what turns the other stars off during that preview. So the honest count is three jobs: fill before the checked star, fill the checked star, and preview on hover. Each rule reads the markup (your HTML) by position, so the radio has to sit directly before its label, in that order — don't wrap them in extra elements or reorder them, or the stars go grey. Here is the map, so when one star looks wrong you know which rule to open: 'label:has(~ input:checked)' fills the stars before the checked one; 'input:checked + label' fills the clicked star itself; and 'label:not(:hover, :has(~ label:hover))' — read as: not the star you're hovering, and not any star sitting after the hovered one — switches the rest off so the hover shows a clean preview.
What the keyboard gets for free
Reload, press the Tab key once, then the right arrow key twice. The form's data read rating=3, and Enter submitted it. I wrote no keyboard code. Radios already move with the arrows because the browser treats same-name radios as one group. That's the part of the work you didn't do, and it's why the picture-only widget can't match it.
The required check works too. Click Send with nothing picked and the form stays put, and the first radio reports "Please select one of these options." In the display:none version that message had nowhere to land. Here the field it points at can actually be focused. The 'focus-visible' rule, which applies only when the keyboard is driving, paints a blue outline on the star the keyboard is standing on, so a keyboard user can see where they are.
The old row-reverse markup you can throw out
If you've looked up "css star rating row-reverse radio buttons", you've seen the old pattern. A sibling selector like '~' only looks forward, so to fill stars before the checked one, tutorials write the radios in the order 5, 4, 3, 2, 1 and flip the row with flex-direction: row-reverse, a CSS rule that lays a row out right to left. It works. It also leaves your HTML saying one thing and your screen saying the opposite, and anything that goes by the markup order sees the stars backwards.
With :has() looking at what comes after a label, the markup can run 1 to 5 in the order a person reads it. You delete the reversed order and the flip. If that's your tutorial's markup, this is the part you get to throw out.
Recap
- The real input holds the value; the label is only the picture.
- Hide radios by shrinking and fading them, not with display:none, so they stay focusable and the required check works.
- ':has()' lets a star react to a checked input after it, so the markup can run 1 to 5.
- Three rules do the work: fill before the checked star, fill the checked star, preview on hover.
- A toggle switch is a checkbox with a good label; a segmented button row or colour swatch picker is radios.
Next, add a sixth control of your own to the file, a checkbox that says "I'd recommend this", and check that Send puts both values in the address bar. If it shows up there, it's real.