29 CSS Checkboxes28 / 29

Pure CSSMIT licensed

Slide-In Label

Spatial hierarchy on check: the label shifts aside and a confirmation tag glides in from the left, adding an elegant extra layer of feedback without a single reflow. Great for save states, applied filters and 'added to X' confirmations.

Published Updated

Live Demo
Try it

The code

<section class="cb-28" aria-label="Slide-in label checkboxes">
  <div class="cb-28__panel">
    <label class="cb-28__row"><input type="checkbox" class="cb-28__input" checked><span class="cb-28__box" aria-hidden="true"></span><span class="cb-28__labels"><span class="cb-28__tag">Saved</span><span class="cb-28__label">Keep in library</span></span></label>
    <label class="cb-28__row"><input type="checkbox" class="cb-28__input"><span class="cb-28__box" aria-hidden="true"></span><span class="cb-28__labels"><span class="cb-28__tag">Saved</span><span class="cb-28__label">Pin to sidebar</span></span></label>
    <label class="cb-28__row"><input type="checkbox" class="cb-28__input"><span class="cb-28__box" aria-hidden="true"></span><span class="cb-28__labels"><span class="cb-28__tag">Saved</span><span class="cb-28__label">Add to watchlist</span></span></label>
  </div>
</section>
.cb-28,
.cb-28 *,
.cb-28 *::before,
.cb-28 *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.cb-28 ::selection {
  background: oklch(0.6 0.14 195);
  color: #fff;
}

.cb-28 {
  --accent: oklch(0.55 0.12 195);
  font-family: 'Segoe UI',system-ui,sans-serif;
  width: 100%;
  min-height: 100vh;
  padding: 40px 20px;
  background: #eef5f6;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cb-28__panel {
  width: min(420px,100%);
  background: #fff;
  border: 1px solid #daeaeb;
  border-radius: 14px;
  padding: 10px 14px;
}

.cb-28__row {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  padding: 14px 8px;
}

.cb-28__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.cb-28__box {
  position: relative;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid #b3ccce;
  background: #fff;
  transition: background .2s,border-color .2s;
}

.cb-28__box::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  transform: scale(.5);
  transition: opacity .2s,transform .2s cubic-bezier(.2,.9,.3,1.2);
  -webkit-mask: no-repeat center/14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  mask: no-repeat center/14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}

.cb-28__labels {
  position: relative;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.cb-28__tag {
  flex: none;
  font: 700 11px ui-monospace,Menlo,monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  padding: 3px 8px;
  border-radius: 6px;
  transform: translateX(-120%);
  opacity: 0;
  transition: transform .35s cubic-bezier(.3,.9,.3,1),opacity .3s;
}

.cb-28__label {
  font-size: 14.5px;
  color: #2a3a3b;
  transform: translateX(-30px);
  transition: transform .35s cubic-bezier(.3,.9,.3,1);
}

.cb-28__input:checked ~ .cb-28__box {
  background: var(--accent);
  border-color: var(--accent);
}

.cb-28__input:checked ~ .cb-28__box::after {
  opacity: 1;
  transform: scale(1);
}

.cb-28__input:checked ~ .cb-28__labels .cb-28__tag {
  transform: translateX(0);
  opacity: 1;
  margin-right: 8px;
}

.cb-28__input:checked ~ .cb-28__labels .cb-28__label {
  transform: translateX(0);
}

.cb-28__input:focus-visible ~ .cb-28__box {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .cb-28__box,
    .cb-28__box::after,
    .cb-28__tag,
    .cb-28__label {
    transition: opacity .2s;
  }

  .cb-28__tag,
    .cb-28__label {
    transform: none;
  }

  .cb-28__input:checked ~ .cb-28__labels .cb-28__tag {
    margin-right: 8px;
  }
}
/* No JavaScript — the confirmation tag slides in via translateX as the label nudges over. */
Paste this into ChatGPT, Claude, Cursor, or any coding assistant. The block below is pre-framed with everything the AI needs to integrate this demo into your project — markup, styles, scoping notes, and the source URL. Hit Copy and paste straight into your chat.
Here's a working CSS Checkboxe from CodeFronts. Use it as-is or adapt to your framework. All classes are scoped under a unique prefix so the code won't collide with your existing styles. MIT licensed.
Demo: Slide-In Label
Source: https://codefronts.com/components/css-checkboxes/slide-in-label/

Spatial hierarchy on check: the label shifts aside and a confirmation tag glides in from the left, adding an elegant extra layer of feedback without a single reflow. Great for save states, applied filters and 'added to X' confirmations.
## HTML
```html
<section class="cb-28" aria-label="Slide-in label checkboxes">
  <div class="cb-28__panel">
    <label class="cb-28__row"><input type="checkbox" class="cb-28__input" checked><span class="cb-28__box" aria-hidden="true"></span><span class="cb-28__labels"><span class="cb-28__tag">Saved</span><span class="cb-28__label">Keep in library</span></span></label>
    <label class="cb-28__row"><input type="checkbox" class="cb-28__input"><span class="cb-28__box" aria-hidden="true"></span><span class="cb-28__labels"><span class="cb-28__tag">Saved</span><span class="cb-28__label">Pin to sidebar</span></span></label>
    <label class="cb-28__row"><input type="checkbox" class="cb-28__input"><span class="cb-28__box" aria-hidden="true"></span><span class="cb-28__labels"><span class="cb-28__tag">Saved</span><span class="cb-28__label">Add to watchlist</span></span></label>
  </div>
</section>
```
## CSS
```css
.cb-28,
.cb-28 *,
.cb-28 *::before,
.cb-28 *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.cb-28 ::selection {
  background: oklch(0.6 0.14 195);
  color: #fff;
}

.cb-28 {
  --accent: oklch(0.55 0.12 195);
  font-family: 'Segoe UI',system-ui,sans-serif;
  width: 100%;
  min-height: 100vh;
  padding: 40px 20px;
  background: #eef5f6;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cb-28__panel {
  width: min(420px,100%);
  background: #fff;
  border: 1px solid #daeaeb;
  border-radius: 14px;
  padding: 10px 14px;
}

.cb-28__row {
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  padding: 14px 8px;
}

.cb-28__input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.cb-28__box {
  position: relative;
  flex: none;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  border: 2px solid #b3ccce;
  background: #fff;
  transition: background .2s,border-color .2s;
}

.cb-28__box::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  transform: scale(.5);
  transition: opacity .2s,transform .2s cubic-bezier(.2,.9,.3,1.2);
  -webkit-mask: no-repeat center/14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  mask: no-repeat center/14px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
}

.cb-28__labels {
  position: relative;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.cb-28__tag {
  flex: none;
  font: 700 11px ui-monospace,Menlo,monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #fff;
  background: var(--accent);
  padding: 3px 8px;
  border-radius: 6px;
  transform: translateX(-120%);
  opacity: 0;
  transition: transform .35s cubic-bezier(.3,.9,.3,1),opacity .3s;
}

.cb-28__label {
  font-size: 14.5px;
  color: #2a3a3b;
  transform: translateX(-30px);
  transition: transform .35s cubic-bezier(.3,.9,.3,1);
}

.cb-28__input:checked ~ .cb-28__box {
  background: var(--accent);
  border-color: var(--accent);
}

.cb-28__input:checked ~ .cb-28__box::after {
  opacity: 1;
  transform: scale(1);
}

.cb-28__input:checked ~ .cb-28__labels .cb-28__tag {
  transform: translateX(0);
  opacity: 1;
  margin-right: 8px;
}

.cb-28__input:checked ~ .cb-28__labels .cb-28__label {
  transform: translateX(0);
}

.cb-28__input:focus-visible ~ .cb-28__box {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
  .cb-28__box,
    .cb-28__box::after,
    .cb-28__tag,
    .cb-28__label {
    transition: opacity .2s;
  }

  .cb-28__tag,
    .cb-28__label {
    transform: none;
  }

  .cb-28__input:checked ~ .cb-28__labels .cb-28__tag {
    margin-right: 8px;
  }
}
```

## JavaScript
```js
/* No JavaScript — the confirmation tag slides in via translateX as the label nudges over. */
```

How this works

Beside the box sit two layers: the main label and a small confirmation tag positioned to its left, initially translated off-position and transparent. On :checked the tag slides into place (translateX → 0, opacity → 1) while the main label nudges over with its own translateX to make visual room — all with transform, so neighbouring rows never shift.

The box gets a standard check. Because everything moves via transform/opacity, the composition stays crisp at 60fps. The native input stays sr-only and focusable with a :focus-visible ring.

Reduced-motion collapses the slide to a simple crossfade so the confirmation still appears without lateral motion.

Make it yours

  • Change the tag copy (Saved, Added, Applied…) and its colour.
  • Adjust slide distance/direction via the tag's start translateX.
  • Tune how far the main label nudges to balance the composition.
  • Recolour the box + tag via --accent.

Gotchas — read before shipping

  • Move both layers with transform, not margins, so the row height/width never changes.
  • Reserve enough horizontal space (or let the tag overlay) so the slide-in doesn't clip.
  • Keep the checkbox the real state; the sliding tag is supplementary feedback.

Browser support

ChromeSafariFirefoxEdge
111+15.4+113+111+

Floor set by oklch() as this demo is written. The core technique itself goes back further — Chrome 49+.

translateX + opacity transitions are universally supported.

Techniques used in this demo

Search CodeFronts

Loading…