# Star Count Button

> A GitHub-style Star button with an attached counter that toggles a filled star when checked.

- Category: [CSS Buttons](https://copy-css.com/category/buttons)
- Tags: github, counter, split pill, favorite, open source
- Live preview: https://copy-css.com/snippets/star-count-button
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<label class="btn-star">
  <input type="checkbox" aria-label="Star this repository">
  <span class="btn-star-main"><svg viewBox="0 0 24 24" aria-hidden="true"><path d="m12 3 2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"/></svg>Star</span>
  <span class="btn-star-count">12.4k</span>
</label>
```

## CSS

```css
.btn-star {
  position: relative;
  display: inline-flex;
  border: 1px solid #d0d7de;
  border-radius: 8px;
  background: #f6f8fa;
  color: #24292f;
  font: 600 14px/1 system-ui, sans-serif;
  cursor: pointer;
  user-select: none;
}

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

.btn-star-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
}

.btn-star svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: #57606a;
  stroke-width: 2;
  stroke-linejoin: round;
  transition: fill 0.15s ease, stroke 0.15s ease, transform 0.15s ease;
}

.btn-star-count {
  padding: 8px 10px;
  border-left: 1px solid #d0d7de;
  font-variant-numeric: tabular-nums;
}

.btn-star:hover {
  background: #eef1f4;
}

.btn-star input:checked + .btn-star-main svg {
  fill: #e3b341;
  stroke: #e3b341;
  transform: scale(1.15);
}

.btn-star:has(input:focus-visible) {
  outline: 2px solid #0969da;
  outline-offset: 2px;
}
```

## Notes

- This CSS Star Count Button is 57 lines of pure CSS (1.0 KB) with no JavaScript and no dependencies. It uses transitions, transforms, 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.
