HTML Form How to - Add validation mark for input field with after pseudo class








Question

We would like to know how to add validation mark for input field with after pseudo class.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
p.required:after {<!--from w w w  .  j  av a  2  s . c  o  m-->
  color: red;
  content: "*";
}
</style>
</head>
<body>
  <p class="required">
    <input type="text" value="First name" class="required" />
  </p>
</body>
</html>

The code above is rendered as follows: