CSS Follow Button
A Follow button that switches to an outlined Following state with a checkmark, using a checkbox.
<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>
.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;
}
About this CSS Follow Button
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). 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
- transitions
- CSS Grid
- 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:
#2563eb#fff#1d4ed8#d4d4d8#18181b#f4f4f5
How to use this follow button
- 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
.btn-followclass 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.