HTML HTML Tutorial HTML Forms HTML Graphics HTML Media HTML APIs HTML Tags



HTML Tag: legend

The <legend> tag is used in HTML to define a caption or a title for a fieldset element. The fieldset element is used to group related elements in a form. The <legend> tag is used to provide a description or a title for the group of related elements.

The <legend> tag is a simple tag that is used to provide a title or a caption for a group of related elements. It is used in conjunction with the <fieldset> tag, which is used to group related elements in a form. The <legend> tag is placed inside the <fieldset> tag and provides a description or a title for the group of related elements.

The <legend> tag is an important tag in HTML because it helps to make forms more accessible to users. By providing a title or a caption for a group of related elements, users can easily understand what information is being requested and how it is related to other information on the form. This can help to improve the user experience and make forms more user-friendly.

Here are some examples of how the <legend> tag can be used in HTML:

Example 1:

<fieldset>
    <legend>Personal Information</legend>
    <label for="name">Name:</label>
    <input type="text" id="name" name="name">
    <label for="email">Email:</label>
    <input type="email" id="email" name="email">
</fieldset>

In this example, the <legend> tag is used to provide a title for the group of related elements. The title is "Personal Information" and it is placed inside the <fieldset> tag. The <label> tags are used to provide labels for the input fields.

Example 2:

<fieldset>
    <legend>Shipping Information</legend>
    <label for="address">Address:</label>
    <input type="text" id="address" name="address">
    <label for="city">City:</label>
    <input type="text" id="city" name="city">
    <label for="state">State:</label>
    <input type="text" id="state" name="state">
    <label for="zip">Zip Code:</label>
    <input type="text" id="zip" name="zip">
</fieldset>

In this example, the <legend> tag is used to provide a title for the group of related elements. The title is "Shipping Information" and it is placed inside the <fieldset> tag. The <label> tags are used to provide labels for the input fields.

Activity