Skip to main content
Practice

Advanced <input> Usage

Using <input /> with <form>

The input tag is often used in conjunction with the <form> tag.

For example, on a signup screen, you can use input tags to get data from the user and then send that data to the server using the <form> tag.

Form Tag Example
<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>

We'll cover more details about input forms in the next lesson.


Using the label Tag

The label tag is used to provide a description or title for the input entry fields.

When using the label tag, the id attribute of the input tag should match the for attribute of the label tag.

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

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

Validation

Validation ensures that the entered information is correct.

The example below uses the required attribute to validate that the input has been filled.

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

Want to learn more?

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