Add a Descriptive Label to a fieldset Element

Description

You can add a legend element to each of your fieldset elements to provide more information.

The legend element must be the first child of a fieldset element.

Example


<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <fieldset>
      <legend>Enter Your Details</legend>
      <p>
        <label for="name">Name: <input id="name" name="name" /></label>
      </p><!-- w w w . j a  v a  2 s  .  c om-->
      <p>
        <label for="name">City: <input id="city" name="city" /></label>
      </p>
    </fieldset>
    <fieldset>
      <legend>Vote For Your Three Favorite Fruits</legend>
      <p>
        <label for="fave1">#1: <input id="fave1" name="fave1" /></label>
      </p>
      <p>
        <label for="fave2">#2: <input id="fave2" name="fave2" /></label>
      </p>
      <p>
        <label for="fave3">#3: <input id="fave3" name="fave3" /></label>
      </p>
    </fieldset>
    <fieldset>
      <legend accesskey="y">
        About <u>Y</u>ou (ALT + Y)
      </legend>
      <p><label for="userName">User name:</label>
         <input type="text" name="txtUserName" size="20" id="userName" />
      </p>
    </fieldset>

    <fieldset>
      <legend accesskey="u">
        About <u>U</u>s (ALT + U)
      </legend>
      <p>
        <label for="referrer">How did you hear about us?</label>:<br/>
        <select name="selReferrer" id="referrer">
          <option selected="selected" value="">Select answer</option>
          <option value="website">Another website</option>
          <option value="printAd">Magazine ad</option>
          <option value="friend">From a friend</option>
          <option value="other">Other</option>
        </select>
      </p>
    </fieldset>
    
    <button>Submit Vote</button>
  </form>
</body>
</html>

Click to view the demo

Note

The code above also shows how to set up the access key for length tag.





















Home »
  HTML CSS »
    HTML »




HTML Introduction
HTML Document
HTML Section
HTML Group Content
HTML Text Marker
HTML Table
HTML Form
HTML Embed