# Size Picker

> Clothing size buttons built on radios, with a filled selected state and a crossed-out sold-out size.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: size, variant, product options, radio, sold out, shop
- Live preview: https://copy-css.com/snippets/size-picker
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<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>
```

## CSS

```css
.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;
}
```

## Notes

- 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.
- the :has() selector: Chrome 105+, Safari 15.4+, Firefox 121+.
- In JSX use `className` instead of `class`. In Tailwind projects put the CSS in the global stylesheet.
