---
meta:
title: Checkbox
description: Checkboxes allow the user to toggle an option on or off.
layout: component
---
```html:preview
Checkbox
```
```jsx:react
import SlCheckbox from '@shoelace-style/shoelace/dist/react/sl-checkbox';
const App = () => Checkbox;
```
:::tip
This component works with standard `
```
{% raw %}
```jsx:react
import { useEffect, useRef } from 'react';
import SlButton from '@shoelace-style/shoelace/dist/react/sl-button';
import SlCheckbox from '@shoelace-style/shoelace/dist/react/sl-checkbox';
const App = () => {
const checkbox = useRef(null);
const errorMessage = `Don't forget to check me!`;
function handleChange() {
checkbox.current.setCustomValidity(checkbox.current.checked ? '' : errorMessage);
}
function handleSubmit(event) {
event.preventDefault();
alert('All fields are valid!');
}
useEffect(() => {
checkbox.current.setCustomValidity(errorMessage);
}, []);
return (
);
};
```
{% endraw %}