CSS Size Picker
Clothing size buttons built on radios, with a filled selected state and a crossed-out sold-out size.
<fieldset class="size-pick">
<legend>Size</legend>
<label><input type="radio" name="size" value="s">S</label>
<label><input type="radio" name="size" value="m" checked>M</label>
<label><input type="radio" name="size" value="l">L</label>
<label><input type="radio" name="size" value="xl">XL</label>
<label><input type="radio" name="size" value="xxl" disabled aria-describedby="size-pick-note">XXL</label>
<small id="size-pick-note">XXL is sold out</small>
</fieldset>
.size-pick {
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: 280px;
margin: 0;
padding: 0;
border: 0;
font-family: system-ui, sans-serif;
}
.size-pick legend {
margin-bottom: 8px;
padding: 0;
color: #1c1917;
font-size: 14px;
font-weight: 700;
}
.size-pick label {
position: relative;
display: grid;
place-items: center;
min-width: 44px;
height: 44px;
padding: 0 8px;
box-sizing: border-box;
border: 1.5px solid #d6d3d1;
border-radius: 10px;
background: #fff;
color: #1c1917;
font-size: 14px;
font-weight: 600;
cursor: pointer;
}
.size-pick input {
position: absolute;
opacity: 0;
pointer-events: none;
}
.size-pick label:hover {
border-color: #1c1917;
}
.size-pick label:has(:checked) {
border-color: #1c1917;
background: #1c1917;
color: #fff;
}
.size-pick label:has(:focus-visible) {
outline: 2px solid #1c1917;
outline-offset: 2px;
}
.size-pick label:has(:disabled) {
border-color: #e7e5e4;
background: linear-gradient(to top right, transparent calc(50% - 1px), #d6d3d1 0 calc(50% + 1px), transparent 0) #fafaf9;
color: #a8a29e;
cursor: not-allowed;
}
.size-pick small {
width: 100%;
color: #78716c;
font-size: 12px;
}
About this CSS Size Picker
This CSS Size Picker is 69 lines of pure CSS (1.2 KB) with no JavaScript and no dependencies. It uses linear gradients, CSS Grid, Flexbox and the :has() selector. 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
- linear gradients
- 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:
#1c1917#d6d3d1#fff#e7e5e4#fafaf9#a8a29e#78716c
How to use this size picker
- 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
.size-pickclass 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.