CSS3 required styles

Horizontally center a div

Using HTML5 required style you can validate your form and show error. But sometimes you need to give a style like keep the color red for error or green on success.

Here is a sample example for required css:

<!DOCTYPE html>
<title>CSS3 styles</title>
<style type="text/css">
  input[type="checkbox"]:required:invalid + label { color: red; }
  input[type="checkbox"]:required:valid + label { color: green; }
<input id="agree" name="agree" type="checkbox" required>
<label for="agree">I accept the <u>Terms and Conditions</u></label>
You may like:  Best place to include script tags in HTML

Leave a Reply

Your email address will not be published. Required fields are marked *