Rock Paper Scissors
import { useId, useState } from 'react';
const css = `
@keyframes radio-rock-paper-shake-a { 0%, 50%, 100% { transform: translateY(0) rotate(0deg); } 25%, 75% { transform: translateY(-10px) rotate(-8deg); } }
@keyframes radio-rock-paper-shake-b { 0%, 50%, 100% { transform: translateY(0) rotate(0deg); } 25%, 75% { transform: translateY(-10px) rotate(-8deg); } }
.radio-rock-paper { display: flex; align-items: center; gap: 20px; }
.radio-rock-paper__stage { position: relative; width: 72px; height: 84px; }
.radio-rock-paper__hand { position: absolute; inset: 0; transform-origin: 50% 100%; }
.radio-rock-paper[data-flip='a'] .radio-rock-paper__hand { animation: radio-rock-paper-shake-a 0.5s ease-in-out; }
.radio-rock-paper[data-flip='b'] .radio-rock-paper__hand { animation: radio-rock-paper-shake-b 0.5s ease-in-out; }
.radio-rock-paper__palm {
position: absolute;
left: 16px;
top: 40px;
width: 38px;
height: 34px;
border-radius: 9px 9px 14px 14px;
background: linear-gradient(light-dark(#42454c, #e5e6e9), light-dark(#5f626a, #a7abb2));
}
.radio-rock-paper__wrist { position: absolute; left: 22px; top: 70px; width: 26px; height: 14px; border-radius: 0 0 4px 4px; background: light-dark(#5f626a, #a7abb2); }
.radio-rock-paper__finger {
--radio-rock-paper-up: 0.28;
--radio-rock-paper-tilt: 0deg;
position: absolute;
top: 12px;
width: 8px;
height: 32px;
border-radius: 4px 4px 2px 2px;
background: linear-gradient(90deg, light-dark(#50535b, #c6c8cd), light-dark(#42454c, #e5e6e9));
box-shadow: inset -1px 0 0 light-dark(#6d7179, #7d8087);
transform-origin: 50% 100%;
transform: rotate(var(--radio-rock-paper-tilt)) scaleY(var(--radio-rock-paper-up));
/* The throw lands as the shake ends. */
transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1) calc(0.45s + var(--i) * 30ms);
}
.radio-rock-paper__thumb {
position: absolute;
left: 6px;
top: 44px;
width: 8px;
height: 22px;
border-radius: 4px;
background: light-dark(#50535b, #c6c8cd);
transform-origin: 100% 100%;
transform: rotate(70deg);
transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1) 0.45s;
}
.radio-rock-paper:has(.radio-rock-paper__input[value='paper']:checked) .radio-rock-paper__finger { --radio-rock-paper-up: 1; --radio-rock-paper-tilt: calc((var(--i) - 1.5) * 5deg); }
.radio-rock-paper:has(.radio-rock-paper__input[value='paper']:checked) .radio-rock-paper__thumb { transform: rotate(-30deg); }
.radio-rock-paper:has(.radio-rock-paper__input[value='scissors']:checked) .radio-rock-paper__finger:nth-child(-n + 2) { --radio-rock-paper-up: 1; --radio-rock-paper-tilt: calc((var(--i) - 0.5) * 22deg); }
.radio-rock-paper__opts { display: grid; gap: 2px; }
.radio-rock-paper__opt {
position: relative;
padding: 4px 10px;
border-radius: 6px;
color: light-dark(#5f626a, #a7abb2);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: color 0.2s, background-color 0.2s;
}
.radio-rock-paper__opt:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-rock-paper__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-rock-paper__opt:has(.radio-rock-paper__input:focus-visible) { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 1px; }
.radio-rock-paper__opt:has(.radio-rock-paper__input:checked) { background: light-dark(#ebedf0, #232529); color: light-dark(#373a40, #f1f2f3); }
@media (prefers-reduced-motion: reduce) {
.radio-rock-paper * { animation: none !important; transition-duration: 0.01s !important; transition-delay: 0s !important; }
}
`;
const MOVES = [
{ value: 'rock', label: 'Rock' },
{ value: 'paper', label: 'Paper' },
{ value: 'scissors', label: 'Scissors' },
];
export function RockPaperRadio() {
const name = useId();
const [flip, setFlip] = useState(0);
return (
<>
<style>
{css}
</style>
<div className="radio-rock-paper" data-flip={flip ? (flip % 2 ? 'a' : 'b') : undefined} onChange={() => setFlip((f) => f + 1)}>
<span className="radio-rock-paper__stage" aria-hidden="true">
<span className="radio-rock-paper__hand">
{/* Index, middle, ring, little: the first two stay up for scissors. */}
<span className="radio-rock-paper__fingers">
{[0, 1, 2, 3].map((i) => (
<span key={i} className="radio-rock-paper__finger" style={{ left: 18 + i * 9, '--i': i } as React.CSSProperties} />
))}
</span>
<span className="radio-rock-paper__wrist" />
<span className="radio-rock-paper__palm" />
<span className="radio-rock-paper__thumb" />
</span>
</span>
<div className="radio-rock-paper__opts" role="radiogroup" aria-label="Your move">
{MOVES.map((m, i) => (
<label key={m.value} className="radio-rock-paper__opt">
<input className="radio-rock-paper__input" type="radio" name={name} value={m.value} defaultChecked={i === 0} />
{m.label}
</label>
))}
</div>
</div>
</>
);
}Markup where the component goes, CSS in your stylesheet, script before </body>. In Vue, Svelte or Angular, call initRadioRockPaper(el) on the mounted element instead.
<div class="radio-rock-paper">
<span class="radio-rock-paper__stage" aria-hidden="true">
<span class="radio-rock-paper__hand">
<span class="radio-rock-paper__fingers">
<span class="radio-rock-paper__finger" style="left:18px;--i:0"></span>
<span class="radio-rock-paper__finger" style="left:27px;--i:1"></span>
<span class="radio-rock-paper__finger" style="left:36px;--i:2"></span>
<span class="radio-rock-paper__finger" style="left:45px;--i:3"></span>
</span>
<span class="radio-rock-paper__wrist"></span>
<span class="radio-rock-paper__palm"></span>
<span class="radio-rock-paper__thumb"></span>
</span>
</span>
<div class="radio-rock-paper__opts" role="radiogroup" aria-label="Your move">
<label class="radio-rock-paper__opt"><input class="radio-rock-paper__input" type="radio" name="radio-rock-paper" checked="" value="rock"/>Rock</label>
<label class="radio-rock-paper__opt"><input class="radio-rock-paper__input" type="radio" name="radio-rock-paper" value="paper"/>Paper</label>
<label class="radio-rock-paper__opt"><input class="radio-rock-paper__input" type="radio" name="radio-rock-paper" value="scissors"/>Scissors</label>
</div>
</div>@keyframes radio-rock-paper-shake-a { 0%, 50%, 100% { transform: translateY(0) rotate(0deg); } 25%, 75% { transform: translateY(-10px) rotate(-8deg); } }
@keyframes radio-rock-paper-shake-b { 0%, 50%, 100% { transform: translateY(0) rotate(0deg); } 25%, 75% { transform: translateY(-10px) rotate(-8deg); } }
.radio-rock-paper { display: flex; align-items: center; gap: 20px; }
.radio-rock-paper__stage { position: relative; width: 72px; height: 84px; }
.radio-rock-paper__hand { position: absolute; inset: 0; transform-origin: 50% 100%; }
.radio-rock-paper[data-flip='a'] .radio-rock-paper__hand { animation: radio-rock-paper-shake-a 0.5s ease-in-out; }
.radio-rock-paper[data-flip='b'] .radio-rock-paper__hand { animation: radio-rock-paper-shake-b 0.5s ease-in-out; }
.radio-rock-paper__palm {
position: absolute;
left: 16px;
top: 40px;
width: 38px;
height: 34px;
border-radius: 9px 9px 14px 14px;
background: linear-gradient(light-dark(#42454c, #e5e6e9), light-dark(#5f626a, #a7abb2));
}
.radio-rock-paper__wrist { position: absolute; left: 22px; top: 70px; width: 26px; height: 14px; border-radius: 0 0 4px 4px; background: light-dark(#5f626a, #a7abb2); }
.radio-rock-paper__finger {
--radio-rock-paper-up: 0.28;
--radio-rock-paper-tilt: 0deg;
position: absolute;
top: 12px;
width: 8px;
height: 32px;
border-radius: 4px 4px 2px 2px;
background: linear-gradient(90deg, light-dark(#50535b, #c6c8cd), light-dark(#42454c, #e5e6e9));
box-shadow: inset -1px 0 0 light-dark(#6d7179, #7d8087);
transform-origin: 50% 100%;
transform: rotate(var(--radio-rock-paper-tilt)) scaleY(var(--radio-rock-paper-up));
/* The throw lands as the shake ends. */
transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1) calc(0.45s + var(--i) * 30ms);
}
.radio-rock-paper__thumb {
position: absolute;
left: 6px;
top: 44px;
width: 8px;
height: 22px;
border-radius: 4px;
background: light-dark(#50535b, #c6c8cd);
transform-origin: 100% 100%;
transform: rotate(70deg);
transition: transform 0.3s cubic-bezier(0.3, 1.5, 0.5, 1) 0.45s;
}
.radio-rock-paper:has(.radio-rock-paper__input[value='paper']:checked) .radio-rock-paper__finger { --radio-rock-paper-up: 1; --radio-rock-paper-tilt: calc((var(--i) - 1.5) * 5deg); }
.radio-rock-paper:has(.radio-rock-paper__input[value='paper']:checked) .radio-rock-paper__thumb { transform: rotate(-30deg); }
.radio-rock-paper:has(.radio-rock-paper__input[value='scissors']:checked) .radio-rock-paper__finger:nth-child(-n + 2) { --radio-rock-paper-up: 1; --radio-rock-paper-tilt: calc((var(--i) - 0.5) * 22deg); }
.radio-rock-paper__opts { display: grid; gap: 2px; }
.radio-rock-paper__opt {
position: relative;
padding: 4px 10px;
border-radius: 6px;
color: light-dark(#5f626a, #a7abb2);
font-size: 12px;
font-weight: 600;
cursor: pointer;
transition: color 0.2s, background-color 0.2s;
}
.radio-rock-paper__opt:hover { color: light-dark(#42454c, #e5e6e9); }
.radio-rock-paper__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; }
.radio-rock-paper__opt:has(.radio-rock-paper__input:focus-visible) { outline: 2px solid light-dark(#5f626a, #a7abb2); outline-offset: 1px; }
.radio-rock-paper__opt:has(.radio-rock-paper__input:checked) { background: light-dark(#ebedf0, #232529); color: light-dark(#373a40, #f1f2f3); }
@media (prefers-reduced-motion: reduce) {
.radio-rock-paper * { animation: none !important; transition-duration: 0.01s !important; transition-delay: 0s !important; }
}function initRadioRockPaper(root) {
var flip = 0;
// Each change flips data-flip between a and b, so the keyframes restart every time.
function onChange() {
flip += 1;
root.setAttribute('data-flip', flip % 2 ? 'a' : 'b');
}
root.addEventListener('change', onChange);
return function () { root.removeEventListener('change', onChange); };
}
document.querySelectorAll('.radio-rock-paper').forEach(initRadioRockPaper);Goal: Create a "Rock Paper Scissors" radio.
Visual behavior: Rock, paper, scissors as a radio group: pick your move and the hand shakes twice, then throws it, fingers unfolding for paper and two of them spreading for scissors.
Technique:
- Real native radios (visually hidden: absolute, 1x1, opacity 0) inside <label>s; the scene is aria-hidden and every state is read from the checked input with :has().
- Four fingers and a thumb are hinged bars; each move sets how far each is raised and how it is angled, and the transitions wait until the shake has finished.
- Effects that should replay on every change (rather than run once) alternate between two identically written keyframes, chosen by a data-flip attribute that flips between a and b on each change, so the browser restarts them.
Accessibility: A role="radiogroup" with an aria-label around native radio inputs sharing one name, so the arrow keys move the choice and Tab enters the group once; :focus-visible on the input outlines its option. Under prefers-reduced-motion the hand changes without the shake.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: neutral only. Black, white and grays, no hues. Use the color values above as written, or my project's closest neutral tokens.
Return a single self-contained component. No dependencies.Goal: Create a "Rock Paper Scissors" radio.
Visual behavior: Rock, paper, scissors as a radio group: pick your move and the hand shakes twice, then throws it, fingers unfolding for paper and two of them spreading for scissors.
Technique:
- Real native radios (visually hidden: absolute, 1x1, opacity 0) inside <label>s; the scene is aria-hidden and every state is read from the checked input with :has().
- Four fingers and a thumb are hinged bars; each move sets how far each is raised and how it is angled, and the transitions wait until the shake has finished.
- Effects that should replay on every change (rather than run once) alternate between two identically written keyframes, chosen by a data-flip attribute that flips between a and b on each change, so the browser restarts them.
Accessibility: A role="radiogroup" with an aria-label around native radio inputs sharing one name, so the arrow keys move the choice and Tab enters the group once; :focus-visible on the input outlines its option. Under prefers-reduced-motion the hand changes without the shake.
My stack: {{USER_STACK}}
My styling: {{USER_STYLING}}
My constraints: {{USER_CONSTRAINTS}}
My colors: use my project's existing color tokens. The color values above are grayscale placeholders. Map each one by its role (surface, text, border, accent, glow) to my theme, and keep their relative lightness so contrast and the effect still read.
Return a single self-contained component. No dependencies.Paste into Claude, ChatGPT or Cursor after filling in {{USER_STACK}}, {{USER_STYLING}} and {{USER_CONSTRAINTS}}. Neutral keeps the greys you see here; Match my project asks the model to map them onto your own colour tokens.
Free to use in any project, commercial included. MIT-0, no attribution required. Licence
About this component
Rock, paper, scissors as a radio group: pick your move and the hand shakes twice, then throws it, fingers unfolding for paper and two of them spreading for scissors.
- Dependencies
- None
- Difficulty
- Intermediate
- Triggers
- click, state change, spring, morph
- Techniques
- css variables, css transition, keyframes
- Reduced motion
- Respected
- Theme
- Light and dark (follows your page's color-scheme)
A role="radiogroup" with an aria-label around native radio inputs sharing one name, so the arrow keys move the choice and Tab enters the group once; :focus-visible on the input outlines its option. Under prefers-reduced-motion the hand changes without the shake.