">
 

label and Input Tag

Iniciado por joomlamz, 28 de Maio de 2026, 11:35

Respostas: 0   |   Visualizações: 15

Tópico anterior - Tópico seguinte

0 Membros e 1 Visitante estão a ver este tópico.

label and Input Tag



Tópico: label and Input Tag
Categoria: Tutoriais | Programação & Tecnologia
Idioma Principal: Português (Conteúdo de Tecnologia)

Descrição do Conteúdo / Informações:
-------------------------------------------------------------------------
1.Input Tag

• The <input> tag defines an input field where users can enter data in a form.

• It is the most important form element in HTML.

• <input> is a self-closing tag (it does not need a closing tag).

• Its behavior changes based on the type attribute:

• type="text" → single-line text box

• type="password" → hidden text

• type="checkbox" → checkbox

4.type="radio" → radio button

5.type="email", type="number", type="date", etc.

Example:

<input type="text" name="username">

2.Label Tag

• The <label> tag represents a caption (text) for a form element like <input>

• It improves accessibility: screen readers read the label when the input is focused.

• Clicking the label text automatically focuses on the associated input field.

• This is especially helpful for small targets like checkboxes and radio buttons.

There are two ways to connect
<label> with <input>:

Method 1: Using for and id (explicit association)

<label for="username">Username:</label>
<input type="text" id="username" name="username">

• for attribute in <label>must match the id of <input>

• This explicitly binds the label to the input.

Method 2: Wrapping input inside label (implicit association)

<label>
Username:
<input type="text" name="username">
</label>

• Here, the <input> is inside the <label>, so for and id are not needed.

• Clicking any part of the label (including the text) focuses the input.

Example:

<form>
<label for="email">Email :</label>
<input type="email" id="email" name="email">



<label for="password">Password:</label>
<input type="password" id="password" name="password">



<label>
<input type="checkbox" name="agree">
I agree to terms
</label>
</form>

• for="email" matches id="email" → label and input are connected.

• Checkbox uses the wrapping method (input inside label).

4. Key Points:

<input>: The field where users enter data (text, password, checkbox, radio, etc.).

<label>: The text that provides a name/description for the input; crucial for accessibility.

for and id : To connect a label with an input, the for attribute must match the id attribute (for = id).

Clicking label: Auto-focuses on the input; makes it easier to click checkboxes and radio buttons.

Screen readers: Reads the label aloud, which is highly important for accessibility.

Reference:

https://www.w3schools.com/tags/tag_input.asp

https://www.geeksforgeeks.org/html/html-label-tag/

https://www.tutorialspoint.com/html/html_label_tag.htm


Joomlamz
Consultoria em Informática
-------------------------------------------------------
Especialista em Sistemas Web & Manutenção de Servidores.
A desenvolver o novo AplPortal com suporte a PHP 8.
Precisa de ajuda profissional? Contacte-me.

Tags: