# Follow Button

> A Follow button that switches to an outlined Following state with a checkmark, using a checkbox.

- Category: [CSS Buttons](https://copy-css.com/category/buttons)
- Tags: toggle, checkbox, following, profile, social
- Live preview: https://copy-css.com/snippets/follow-button
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<label class="btn-follow">
  <input type="checkbox" aria-label="Follow">
  <span class="btn-follow-off" aria-hidden="true">+ Follow</span>
  <span class="btn-follow-on" aria-hidden="true">✓ Following</span>
</label>
<label class="btn-follow">
  <input type="checkbox" aria-label="Follow" checked>
  <span class="btn-follow-off" aria-hidden="true">+ Follow</span>
  <span class="btn-follow-on" aria-hidden="true">✓ Following</span>
</label>
```

## CSS

```css
.btn-follow {
  position: relative;
  display: inline-grid;
  min-width: 128px;
  padding: 11px 20px;
  border: 1.5px solid #2563eb;
  border-radius: 999px;
  background: #2563eb;
  color: #fff;
  font: 600 15px/1 system-ui, sans-serif;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.btn-follow input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

/* Both labels share one grid cell, so the width never jumps */
.btn-follow span {
  grid-area: 1 / 1;
}

.btn-follow-on {
  visibility: hidden;
}

.btn-follow:hover {
  background: #1d4ed8;
}

.btn-follow:has(input:checked) {
  border-color: #d4d4d8;
  background: #fff;
  color: #18181b;
}

.btn-follow:has(input:checked):hover {
  background: #f4f4f5;
}

.btn-follow input:checked ~ .btn-follow-off {
  visibility: hidden;
}

.btn-follow input:checked ~ .btn-follow-on {
  visibility: visible;
}

.btn-follow:has(input:focus-visible) {
  outline: 2px solid #2563eb;
  outline-offset: 3px;
}
```

## Notes

- This CSS Follow Button is 59 lines of pure CSS (1.1 KB) with no JavaScript and no dependencies. It uses transitions, CSS Grid, the :has() selector and the :checked state (no JavaScript).
- 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.
