HTML Forms
An HTML form allows users to submit data to a server for processing. Let's add some functionality to our previous HTML form to allow queries to Google Search.
The necessary attributes
First, we need to add some attributes to the <form>
tag. But what attributes does it accept? Let's look at two of them.
The method
attribute
method
attributeThis specifies the HTTP request method to use. By default, this method is "GET", but there are 4 other possibilities: "POST", "DELETE", "PUT" and "PATCH". In our case, Google Search expects a GET request, so the "GET" value is fine. This means we do not need to specify a method
this time.
The action
attribute
action
attributeThis attribute specifies the URL to submit the form data to. Let's figure out what the action URL should be for our form.
Go to the Google homepage and enter some search query. Then look at the URL bar and see what address it went to.


As we see above, the URL it went to was https://www.google.com/search
. Hence this is the URL we need to submit our form data to. Let's add this attribute to our <form>
tag:
<form action="https://www.google.com/search">...</form>
The name
attribute
name
attributeThis attribute is given to an input field, and specifies the name of the input parameter. In this case, what name do we give our input?
Consider the URL bar again. Right after the ?
, you should see something along the lines of q=whateveryoutyped
.

This is how form data is arranged in a GET request. The name of the parameter, following by an equals sign =
, followed by the value of the parameter itself. For multiple parameters, they are separated by ampersand symbols &
. In general, in a GET request, the URL bar looks like this:
https://www.domain.com/action-url?name1=value1&name2=value2&name3=value3
For Google Search, most of the parameters are for Google's internal service: type of browser, operating system, cookies, google account signed in, etc. But the one we want is the first one: q=
Here q
is the name of the parameter, and it stands for (presumably) query. Whatever you searched up would be the value. So now we know what name to give our <input>
field:
<input name="q" placeholder="query" required>
Putting it together
Your form by now should look like this:
<form action="https://www.google.com/search">
<input name="q" placeholder="query" required>
<button type="submit">Submit</button>
</form>
Once you reload the page, you won't notice any visible changes. But when you enter a query into the form field, you'll be redirected to a Google Search page for the query as below.

Next steps
We're pretty much done with HTML for now. The next section of the guide will explain a little about the Browser Inspector in Firefox, a tool that will be very useful when we move on to CSS right after.
Last updated