HTML Form How to - Mark Required field








Question

We would like to know how to mark Required field.

Answer


<!--from ww  w .j  a  v  a  2 s. c  om-->
<html>
<head>
<style>
fieldset {
  font-size: 12px;
  padding: 10px;
  width: 400px;
}

span.required {
  font-weight: bold;
  font-size: 20px;
  color: #ff0000;
}

td {
  font-size: 12px;
}
</style>
</head>
<body>

  <form name="frmExample" action="" method="post">
    <fieldset>
      <legend>Contact details</legend>

      <table>
        <tr>
          <td class="label">Phone number <span class="required">*</span></td>
          <td>Area code:&nbsp;<input type="text" name="txtTelAreaCode"
            size="5" /> Number:&nbsp;<input type="text" name="txtTelNo"
            size="10" /></td>
        </tr>
      </table>

    </fieldset>
  </form>

</body>
</html>

The code above is rendered as follows: