The Form Element

HTML forms are a way to get data from users. You use them on the internet all the time, often without noticing: whenever you type into a search box, log in, sign up or choose from several options, you're filling in a form.

In this lesson, we'll look at how forms are built and which elements we use to collect data. Step by step, we'll create a sign-up form for a course.

A form is created with the form element. The form collects information, but then it has to send it somewhere to be processed. That's why the form element has two attributes:

  • action: the URL the form data is sent to.
  • method: how the data is sent (the method of the HTTP request).

The two most common methods are:

  • GET (used when we leave out method): the data is added to the page address, for example /search?q=cats. That suits a search, because the address with the results can be saved or shared.
  • POST: the data is sent inside the request, not in the address. We use it, for example, for logging in and signing up, so that a password doesn't end up in the address.

For now, you don't need to know what exactly an HTTP request is.

<form action="/processing.html" method="POST">
</form>

Instructions

Create a form element with the attribute action with the value /exercise.html and the attribute method with the value POST. You won't see the form yet: it stays invisible until we add inputs to it.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

1/11