Free Ebook cover Complete HTML, CSS and Javascript course to become a Front End Developer

Complete HTML, CSS and Javascript course to become a Front End Developer

3.79

(14)

125 pages

Forms and inputs in HTML

Capítulo 42

Estimated reading time: 4 minutes

+ Exercise
Audio Icon

Listen in audio

0:00 / 0:00

Forms are an essential part of a user's interaction with a web page. They allow users to input data that can be sent to a server for processing. Forms can be used for things like searching, logging in, signing up, and more. In this chapter, we will discuss how to create forms and use different input types in HTML.

HTML Forms

HTML forms are created using the <form> tag. The <form> acts as a container for different form elements like input fields, buttons, and more.

<form action="/submit" method="post">
  <!-- form elements here -->
</form>

The 'action' attribute in the <form> Specifies where form data should be sent when the form is submitted. The 'method' attribute specifies how form data should be submitted. The most common methods are 'get' and 'post'.

Inputs in HTML

Input fields are used to collect user data. They are created using the <input> tag. There are many different types of input fields that can be used, depending on the type of data you want to collect.

Text

To collect a single line of text, you can use the 'text' input type.

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

<input type="text" name="firstname" id="firstname">

The 'name' attribute is used to identify the input field when data is sent. The 'id' attribute is used to identify the input field in CSS and JavaScript.

Password

To collect a password, you can use the 'password' input type. This hides characters as they are typed.

<input type="password" name="password" id="password">

Email

To collect an email address, you can use the 'email' input type. This automatically validates the field to ensure a valid email address is entered.

<input type="email" name="email" id="email">

Buttons

Buttons are used to submit the form. They are created using the <button> or the <input> with the type set to 'submit'.

<button type="submit">Submit</button>
<input type="submit" value="Submit">

Other types of input

There are many other input types you can use, including 'radio', 'checkbox', 'file', 'date', 'color' and more. Each type has its own specific characteristics and uses.

Conclusion

Forms and input fields are an essential part of building interactive websites. They allow you to collect user data and send it to a server for processing. By understanding how to use different types of input fields, you can create more efficient and effective forms that meet your users' needs.

Practice creating different types of forms and using different types of input. Experiment with different attributes and see how they affect your form's behavior. Remember, the best way to learn is by doing!

Now answer the exercise about the content:

What is the function of the <form> in HTML and what attributes are commonly used with it?

You are right! Congratulations, now go to the next page

You missed! Try again.

The <form> tag in HTML serves as a container for various form elements such as input fields and buttons. It is mainly used to facilitate user interaction by allowing data input and submission to a server. The most commonly used attributes with <form> are action and method, where action defines the form submission URL and method specifies the submission protocol, typically get or post.

Next chapter

Introduction to CSS: selectors, properties and values

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.