Skip to main content

Three Most Common HTML Form Elements You Should Know

When I visited the Facebook page at the first time, it required me to sign up. Therefore, I completed the sign up form to create my new account.


The form is very simple to fill in because it only asks for very common information such as full name, phone number, new password, birthday, and gender. It only took me one or two minutes to finish the form.

Not only Social media sites require us to sign up first before we post anything, but many business or eCommerce sites also ask us to create new account before we take any action.

For example, when I go to the Origins skin care site, it will pop up a email sign up form window. To encourage new customers to sign up, it gives a 15% off for the first order. It is definitely an attractive call-to-action message.


Anyway, if your website requires users to sign up, you need to know how to create a HTML form.

Yesterday, I just learned how to build a simple HTML form from Udemy course. And it is not that hard. All you need to know is these three elements: <form>, <input> and <label>.

Study Notes:

<form>

According to MDN Web Doc, HTML forms are the one of the main points of interaction between a user and a website or application.

The HTML form includes five main widgets:

  • text
  • button
  • radio
  • select box
  • checkbox
When you start to create a form, you need to enter <form></form> element inside the <body></body> element, so the screen-reader will know that there will be a form on the web page.

A form includes two attributes: 
  • action: the URL to send form data to
  • method: the type of the http request, which has two values-"get" or "post"
For example:

<body>
    <form action="my form submitting page URL" method="post">
<!--you put your input here-->
    </form>
</body>

<input>

The <input> tag creates interactive controls. The "type" attribute determines the type of input.

For example:

  • <input type="text">
  • <input type="date">
  • <input type="color">
  • <input type="file">
  • <input type="checkbox">
With the <input> tag, we can use the following code to create a very simple HTML form now:

<!DOCTYPE html>

<html>
<head>
<title>Form</title>
</head>
<body>
<h1>Sign In</h1>
<form action="http://www.wikipedia.org" method="get">
<input type="text" placeholder="username">
<input type="password" placeholder="password">
<input type="submit" >
</form>
</body>
</html>

When you put the code in your Editor, the outcome will be:



Note: The "placeholder" attribute can allow the " username "to show on the "text box". Users can read the word "username", so it helps them to understand what kind of information belongs to this area.

<label>

Labels are very important to making website accessible. What are the labels? Labels are the "name" or "title" of the input area.

For example, the Facebook login form shows two labels, which are "Email or Phone" and "Password".


The <label></label> element needs to match with <input> tag:

<form action: "sign in page url" method="post">

   <label for="username">Username</label>
   <input id="username" type="text">

</form>

Note: the use of the "for" attribute should on all <label>

I add the <label></label> element on the previous "sign in" page.


The new Sign In page will be:

From the new page, you can see "username" and "password" labels are in front of input box.

Comments

Popular posts from this blog

GIT Study Note: Six Git Commands You Should Know!

What is Git? According to Git website , Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Basically, we can use Git to track all of changes and revert them back if we made mistakes. The version control system is a way for us to work with different versions of our code, so that we can save different features and make notes as we progress. It is also very useful for team collaboration. Six Git Command You Should Know 1. Git Init In our server, we need to create a "Git" directory and inside of "Git", we make another direcory "git_inro". Then, we add a file "app,js" in the "git_intro" folder. The first thing we need to run is "git init" . When we run git init, it will make a directory which is hidden called ".git". Wherever I run that git init command, it's going to track all of our changes. ...

Intermediate Express.js: How To Render HTML From A EJS File?

The Express.js apps we have developed so far are just simply getting requests from users and sending matched message back to them. However, it is not what we want in the real web application. In most case, we want to send back a relevant web page when our app receives request from user. In order to do that, we need to npm install ejs file in the Express, create HTML page in the ejs file, and render HTMl from the ejs file. I know it sounds confuse now. I am going to explain more details in the example. EJS stands for embedded JavaScript. It lets us embed JavaScript code variables if statements loops inside of HTML. How to render HTML from a EJS file? Step One: Create a HTML page in EJS file Firstly, in our server, we create a folder named "EJSDemo". In this folder, we touch two files, one is "app.js", and the other one is "home.ejs". We are going to write a simple HTML code in the "home.ejs" file. The instructor create a dog page,...

Express Study Notes: Five Steps To Develop My First Express App

In the last post, I shared my study note about one of the most important reason that Node is very popular is because Node has the largest package ecosystem of open source libraries in the world. Node's NPM, the package manager for Javascript, contains almost 200,000 packages which are centralized on the NPM website. And more importantly, NPM has a command line tool which help us to install packages really easily. The course instructor told us that we are going to learn Express.js to develop Apps in this course. screenshot for the Express.js.com homepage What is Express.js? Express.js is a web development framework. According to the course, framework is a bunch of code that someone else wrote just like a library is except when we use a framework, we have less control. The goal of using this framework is to make our development of APPs faster. Why do we use Express.js? 1. It is the most popular Node web development framework so far. 2. It is a very lightweight ...