HTML Forms: Total Domination
Sobre a Aula

Let’s explore two important elements for structuring and organizing HTML forms: <fieldset> and <legend>.

These elements are crucial for creating more accessible and understandable forms, especially when it comes to grouping related data.

The <fieldset> element’s main function is to group related data in a form.

This means that it creates a kind of visual outline or box around a specific set of input fields or related elements, indicating that these elements are logically connected.

This visual organization makes the user experience clearer and more understandable, especially in longer forms.

To provide a meaningful description or title for the set of data grouped by the <fieldset>, we use the <legend> element.

The <legend> defines a caption that is displayed above or next to the <fieldset>, providing additional information about the group of elements.

See the example:

<form action="/action_page.php">
  <fieldset>
    <legend>Personalia:</legend>
    <label for="fname">First name:</label><br>
    <input type="text" id="fname" name="fname" value="John"><br>
    <label for="lname">Last name:</label><br>
    <input type="text" id="lname" name="lname" value="Doe"><br><br>
    <input type="submit" value="Submit">
  </fieldset>
</form>

This is crucial to enhance the accessibility and understanding of form content, especially for users relying on screen readers.

By understanding how to use the <fieldset> and <legend> elements, novice developers can create more organized and user-friendly forms.

The ability to group related fields and provide a descriptive legend not only aids in the form’s aesthetics but also improves usability and user comprehension, contributing to a more intuitive form-filling experience.

Entrar na conversa
Rolar para cima