fieldset and legend

Used to group related choices and even sets.

fieldset and legend elements can further help group related input fields.

Example 3.13 - Form fieldset and legend elements - Example 3.13

 <form method="get" action="https://cscie12.dce.harvard.edu/echo">
   <div>
     <fieldset>
       <legend>Name       </legend>
       <label for="fname">First Name       </label>
       <input type="text" name="fname" id="fname" size="30"/>

       <br/>

       <label for="lname">Last Name       </label>
       <input type="text" name="lname" id="lname" size="30"/>

       <br/>
     </fieldset>
     <fieldset>
       <legend>Sports       </legend>
       <fieldset>
         <legend>Do you like basketball?         </legend>
         <input type="radio" name="basketball" id="basketball_yes" value="Y"/>

         <label for="basketball_yes">Yes         </label>
         <br/>

         <input type="radio" name="basketball" id="basketball_no" value="N"/>

         <label for="basketball_no">No         </label>       </fieldset>
       <fieldset>
         <legend>Do you like baseball?         </legend>
         <input type="radio" name="baseball" id="baseball_yes" value="Y"/>

         <label for="baseball_yes">Yes         </label>
         <br/>

         <input type="radio" name="baseball" id="baseball_no" value="N"/>

         <label for="baseball_no">No         </label>       </fieldset>     </fieldset>
     <input type="submit" value="Submit"/>

   </div>
 </form>
Name

Sports
Do you like basketball?
Do you like baseball?