# Checkbox [component-header:sl-checkbox] ```html preview Checkbox ``` ```jsx react import { SlCheckbox } from '@shoelace-style/shoelace/dist/react'; const App = () => Checkbox; ``` ?> This component works with standard `
` elements. Please refer to the section on [form controls](/getting-started/form-controls) to learn more about form submission and client-side validation. ## Examples ### Checked Use the `checked` attribute to activate the checkbox. ```html preview Checked ``` ```jsx react import { SlCheckbox } from '@shoelace-style/shoelace/dist/react'; const App = () => Checked; ``` ### Indeterminate Use the `indeterminate` attribute to make the checkbox indeterminate. ```html preview Indeterminate ``` ```jsx react import { SlCheckbox } from '@shoelace-style/shoelace/dist/react'; const App = () => Indeterminate; ``` ### Disabled Use the `disabled` attribute to disable the checkbox. ```html preview Disabled ``` ```jsx react import { SlCheckbox } from '@shoelace-style/shoelace/dist/react'; const App = () => Disabled; ``` ### Custom Validity Use the `setCustomValidity()` method to set a custom validation message. This will prevent the form from submitting and make the browser display the error message you provide. To clear the error, call this function with an empty string. ```html preview Check me
Submit
``` ```jsx react import { useEffect, useRef } from 'react'; import { SlButton, SlCheckbox } from '@shoelace-style/shoelace/dist/react'; 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 (
Check me
Submit
); }; ``` [component-metadata:sl-checkbox]