Open In App
Related Articles

CSS :required Selector

Improve Article
Save Article
Like Article

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>. 


:required {
    // CSS Property

Example: In this example we are using CSS required selector.


<!DOCTYPE html>
    <title>:required Selector</title>
        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;
    <h2>:required selector</h2>
            <label for="name">Name</label>
            <input type="text" name="name" id="name" />
            <label for="email">Email</label>
            <input type="email" name="email" id="email" required />
            <input type="submit" value="Submit" />



Supported Browsers: The browser supported by :required Selector are listed below:

  • Apple Safari 5.0
  • Google Chrome 10.0
  • Edge 12.0
  • Firefox 4.0
  • Opera 10.0

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 05 Jul, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials