# Terms Consent Checkbox

> A required "I agree to the terms" checkbox with a link, which turns red with a message only after a failed submit.

- Category: [CSS Form Elements](https://copy-css.com/category/forms)
- Tags: terms, consent, agree, required, user-invalid, gdpr
- Live preview: https://copy-css.com/snippets/terms-consent-checkbox
- License: Free for personal and commercial use. No signup, no attribution required.

## HTML

```html
<form class="consent">
  <label>
    <input type="checkbox" required aria-describedby="consent-error">
    <span>I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>.</span>
  </label>
  <p id="consent-error" class="consent-error">Please accept the terms to continue.</p>
  <button type="submit">Create account</button>
</form>
```

## CSS

```css
.consent {
  display: grid;
  gap: 10px;
  width: 260px;
  color: #1f2937;
  font: 14px/1.45 system-ui, sans-serif;
}

.consent label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.consent input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
  accent-color: #4f46e5;
  cursor: pointer;
}

.consent input:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}

.consent a {
  color: #4f46e5;
  font-weight: 600;
}

.consent a:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
  border-radius: 2px;
}

.consent-error {
  display: none;
  margin: -4px 0 0 28px;
  color: #dc2626;
  font-size: 13px;
}

.consent:has(input:user-invalid) .consent-error {
  display: block;
}

.consent input:user-invalid {
  outline: 2px solid #dc2626;
  outline-offset: 1px;
}

.consent button {
  padding: 10px;
  border: 0;
  border-radius: 10px;
  background: #4f46e5;
  color: #fff;
  font: 600 14px system-ui, sans-serif;
  cursor: pointer;
}

.consent button:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}
```

## Notes

- This CSS Terms Consent Checkbox is 70 lines of pure CSS (1.1 KB) with no JavaScript and no dependencies. It uses CSS Grid, Flexbox, the :has() selector and keyboard focus styles.
- 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.
