CSS :default Selector
The :default selector is used to set a default element in a group of same type of element in a form. This selector is used on button, option, radio button and check-box.
Syntax:
:default {
//property
}
Example:
<!DOCTYPE html>
<html>
<head>
<style>
input[type="checkbox"]:default {
box-shadow: 0 0 1px 1px gray;
}
</style>
</head>
<body>
<h3>Select Language</h3>
<form action="">
<input type="checkbox" name="lan" value="c" checked> C
<br>
<input type="checkbox" name="lan" value="c++"> C++
<br>
<input type="checkbox" name="lan" value="java"> Java
<br>
<input type="checkbox" name="lan" value="c#"> C#
<br>
<input type="checkbox" name="lan" value="python"> Python
<br>
<input type="checkbox" name="lan" value="javascript"> JavaScript
<br>
</form>
</body>
</html>
Output:
Supported Browsers:
- Google Chrome 10.0
- Edge 79.0
- Firefox 4.0
- Safari 5.0
- Opera 10.0
CSS :default Selector – FAQs
What does the :default selector do in CSS?
The :default selector targets the default form element in a group, such as the pre-selected radio button or option in a select menu.
How do I style the default option in a dropdown menu?
Use :default, like option:default, to style the default option in a select dropdown.
Can the :default selector be combined with other selectors?
Yes, the :default selector can be combined with other selectors to narrow down its use, such as with class or type selectors.
Is the :default selector supported by all browsers?
The :default selector is supported in most modern browsers, but compatibility may vary with older versions.
Does :default work with all form controls?
The :default selector primarily works with form controls like radio buttons, checkboxes, and select options that can have a default state.