Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

Advanced Usage of input Tag

The input tag is most commonly used with the <form> tag.

For example, on a signup page, the input tag allows the user to enter data, and the <form> tag is used to send this data to the server.

Example of Using form Tag
<form action="/submit" method="post">
<input type="text" name="username" placeholder="Username" />
<input type="password" name="password" placeholder="Password" />
<input type="submit" value="Submit" />
</form>

More details about input forms will be covered in the next lesson.


Using the label Tag

The label tag is used to define a label for an input field, providing a description or a title.

When using the label tag, ensure that the id of the input tag matches the for attribute of the label tag.

Example of Label Tag
<label for="username">Username:</label>

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

Validation

Validation refers to checking if the entered information is correct.

The input below uses the required attribute to validate whether the input has a value.

Validation Using Required Attribute
<input type="email" name="useremail" required />

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.