CSS | :required Selector
The required selector is used to select the required element with the required attribute and set the CSS property. Required attributes of Form elements are defined as required.
Note: This selector is used with form elements, eg. <input>, <select> and <textarea>.
Syntax:
:required { // CSS Property }
Example:
<!DOCTYPE html> < html > < head > < title >:required Selector</ title > < style > h1 { color: green; } body { text-align:center; } input:required { background-color: green; color: white; } form div { padding: 10px; } label { display: block; font-size: 18px; } input { border: 1px solid black; padding: 9px; font-size: 18px; } </ style > </ head > < body > < h1 >GeeksforGeeks</ h1 > < h2 >:required selector</ h2 > < form > < div > < label for = "name" >Name</ label > < input type = "text" name = "name" id = "name" /> </ div > < div > < label for = "email" >Email</ label > < input type = "email" name = "email" id = "email" required /> </ div > < div > < input type = "submit" value = "Submit" /> </ div > </ form > </ body > </ html > |
chevron_right
filter_none
Output:
Supported Browsers: The browser supported by :required Selector are listed below:
- Apple Safari 5.0
- Google Chrome 10.0
- Firefox 4.0
- Opera 10.0
- Internet Explorer 10.0
Recommended Posts:
- CSS | ::after Selector
- CSS | ::before selector
- CSS | * Selector
- CSS | #id Selector
- CSS | :not Selector
- jQuery | #id Selector
- CSS | [attribute|=value] Selector
- jQuery | :has() Selector with example
- CSS | :nth-child() Selector
- jQuery | :contains() Selector
- CSS | :hover Selector
- CSS | [attribute^=value] Selector
- CSS | [attribute~=value] Selector
- CSS | [attribute$=value] Selector
- CSS | :nth-last-child() Selector
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.