# Format Toggle Buttons

> A text editor toolbar of bold, italic, underline and strike toggles that stay pressed when on.

- Category: [CSS Buttons](https://copy-css.com/category/buttons)
- Tags: bold, italic, toolbar, editor, pressed, checkbox
- Live preview: https://copy-css.com/snippets/format-toggle-buttons
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<fieldset class="format-toggles">
  <legend class="format-toggles-legend">Text style</legend>
  <label><input type="checkbox" aria-label="Bold" checked><b aria-hidden="true">B</b></label>
  <label><input type="checkbox" aria-label="Italic"><i aria-hidden="true">I</i></label>
  <label><input type="checkbox" aria-label="Underline"><u aria-hidden="true">U</u></label>
  <label><input type="checkbox" aria-label="Strikethrough"><s aria-hidden="true">S</s></label>
</fieldset>
```

## CSS

```css
.format-toggles {
  display: inline-flex;
  gap: 2px;
  margin: 0;
  padding: 4px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 2px #0f172a14;
}

.format-toggles-legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.format-toggles label {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #475569;
  font: 17px/1 Georgia, "Times New Roman", serif;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.format-toggles input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.format-toggles label:hover {
  background: #f1f5f9;
  color: #0f172a;
}

.format-toggles label:has(input:checked) {
  background: #e0e7ff;
  color: #3730a3;
}

.format-toggles label:has(input:focus-visible) {
  outline: 2px solid #4f46e5;
  outline-offset: 1px;
}
```

## Notes

- This CSS Format Toggle Buttons is 55 lines of pure CSS (1.0 KB) with no JavaScript and no dependencies. It uses transitions, box shadows, clip paths and CSS Grid.
- 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.
