CSS3 > Selectors

Required selector in CSS3

How to add style to the required form elements in CSS3?


By using required selector we can add style to the required elements. Required selector is only applies to the form elements (input,elect and text area).

<style>
    input:required {
        background-color: pink;
    }
</style>

<body>
    <h3>Required selector</h3>
    <form>
        First name
        <input type="text" name="txt" required />*<br />
        Middle name
        <input type="text" name="txt" /><br />
        Last name<input type="text" name="txt" required />*
    </form>
</body>

In the above code snippet we have given style to the required selector. So, that it will find the required attribute in the <input> elements and applies the given style.

OUTPUT

 Views: 3333 | Post Order: 32



Write for us






Hosting Recommendations