In CSS, the :checked and :not(:checked) pseudo-classes are used to select and style HTML form elements, specifically radio buttons and checkboxes, based on whether they are checked (selected) or not. These pseudo-classes allow you to customize the appearance of these input elements depending on their checked or unchecked state.
:checked Pseudo-Class: This pseudo-class selects form elements that are currently checked or selected. It is primarily used for styling radio buttons and checkboxes when they are in the checked state.
:not(:checked) Pseudo-Class: Conversely, the :not(:checked) pseudo-class selects form elements that are currently not checked or unselected. It is useful for styling radio buttons and checkboxes when they are in the unchecked state.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Input pseudo-classes</title> <style> input[type="radio"]:checked + label { color: blue; } input[type="radio"]:not(:checked) + label { color: red; } </style> </head> <body> <h3>Input pseudo-classes</h3> <p>:checked | not(:checked)</p> <input type="radio" name="gender" id="male" checked /> <label for="male">Male</label> <input type="radio" id="female" name="gender" /> <label for="female">Female</label> </body> </html>
The provided CSS code is used to style labels that are associated with radio buttons based on whether the radio button is checked or not.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions