CSS :checked
Pseudo-Class
The :checked
pseudo-class applies styles to checkboxes, radio buttons, and switches when they are selected (checked).
1. Basic Usage
✅ Styling a Checked Checkbox
✅ Changes the background color of a checked checkbox.
2. Styling a Checked Radio Button
✅ Adds a blue outline to a selected radio button.
3. Showing & Hiding Elements Based on Check State
✅ Show a Message When Checkbox is Checked
✅ The message appears only when the checkbox is checked.
4. Creating a Custom Toggle Switch
✅ A toggle switch effect using :checked
.
5. When to Use :checked
?
✔ Custom checkboxes and radio buttons
✔ Toggling UI elements dynamically
✔ Building interactive forms without JavaScript