Forms and Forms Element

Updated in 6th of June 2025

Programming or Coding

Imagine you`re building a simple website, maybe for a survey, a contact page, or even a tiny online shop. How do you get information from your website visitors? That`s where HTML Forms come in.

Think of an HTML form as a special kind of blank paper or a digital questionnaire you put on your website. It`s designed to collect information from the person Browse your page.


The Super Simple Analogy - A Pizza Order Form

Let`s say you`re making an online pizza order. What kind of information would you need from your customer?

  • Their name
  • Their favorite pizza toppings
  • How many pizzas they want
  • Their delivery address
  • Maybe if they want to pay with cash or card

An HTML form helps you create all those little boxes, buttons, and menus for your customer to fill out.


The Basic Building Blocks: What`s Inside a Form?

Inside your <form> tag, you`ll place various input elements to get different types of information.

#1. <input> Tag

This is the most versatile form element. Its behavior changes dramatically based on its type attribute.

    • type="text": For single-line text input (names, addresses, etc.).



    • type="password": For sensitive text input; characters are masked.


    • type="email": For email addresses; browsers might offer basic validation.


    • type="number": For numerical input; browsers often show up/down arrows.


    • type="checkbox": For selecting one or more options from a list.


    • type="radio": For selecting exactly one option from a group (use the same name for a group).


    • type="submit": Creates a button that, when clicked, submits the form


    • type="button": Creates a generic button (doesn`t submit the form by default, often used with JavaScript).


    • type="date": For picking dates.


    • type="file": For allowing users to upload files.



Important input attributes:

    • id: A unique identifier for the element (important for connecting with labels and CSS/JS).
    • name: Crucial! This is the name that the server will use to identify the data coming from this input field.
    • value: The initial value of the input or the value sent when the input is submitted (especially for checkboxes, radio buttons, and submit buttons).
    • placeholder: Light gray text inside a text input field, giving a hint to the user.
    • required: Makes the field mandatory; the form won`t submit unless it`s filled.


#2. 

<label> Tag


This is incredibly important for accessibility and user experience. It explicitly links a text label to an input field.


  • Use the for attribute in the <label> tag, and set its value to the id of the input it`s labeling.
  • Benefits:
    • Screen readers can associate the label with the input.
    • Users can click on the label text to focus on (or select) the input field.

Putting everything together



ACTION PLAN

Continuous practice is key! Click HERE to jump into our online compiler and master all the code you see.

 Note - In the compiler, you can switch between CODE & DISPLAY as shown below:




This 8-minute video below summarizes everything we`ve just covered. Feel free to watch it repeatedly to fully master this module.



OTHER CONTENTS