HTML – Forms

  • HTML forms are very important part of web development, allowing users to input and submit data to a server.
  • HTML forms are used for various purposes, including user registration, contact forms, search boxes, and more.

Example:

form-example

Inside the <form >

block-inline

Label:

  • The <label> element, which provides a text description for the input field.

Syntax:

<label></label>
laebl-image

🚀 Try it yourself! Click the button below to run the code and see the output in action.

HTML Code

Output

Input:

  • The <input> element is used so that the user can enter information. Input field is created using this tag. It is a self-closing tag.

Syntax:

<input type=”text”>
laebl-image

🚀 Try it yourself! Click the button below to run the code and see the output in action.

HTML Code

Output

Note: The <form> element is a container for different types of input elements, such as: text fields, checkboxes, radio buttons, submit buttons, etc.

Form attributes

block-inline

Action:

  • The action attribute specifies the URL or server-side script to which the form data should be submitted when the user clicks the submit button.
  • The value of the action attribute is typically a URL or a relative path.

Example:

form-action-submit

Method:

  • Defines the HTTP method to be used when submitting the form data to the server.
  • It can be either “GET” or “POST”

GET

  • GET When the method is set to“GET”, the form data is appended to the URL as query parameters and sent as part of the URL string. In this method, form data is visible in the URL.

Example:

form-action-get

POST

  • When the method is set to “POST”, the form data is sent in the body of the HTTP request. This method is suitable for sending sensitive or large amounts of data that should not be exposed in the URL.
  • It is commonly used for submitting forms that create, update, or delete data on the server.

Example:

form-action-post

The HTML <form> Elements

  • <form> – Used for HTML form for user input
  • <input> – Used for input control
  • <textarea> – Used for multiline input control (text area)
  • <label> – Used for label for an <input> element
  • <fieldset> – Groups related elements in a form
  • <legend> – Used for caption for a <fieldset> element
  • <select> – Used for drop-down list
  • <optgroup> – A group of related options in a drop-down list
  • <option> – Used for option in a drop-down list
  • <button> – Used for clickable button
  • <datalist> – Used for list of pre-defined options for input controls
  • <output> – Used for result of a calculation

HTML Input Types

Syntax:

class-image

🚀 Try it yourself! Click the button below to run the code and see the output in action.

HTML Code

Output

Note: Above are all input types with output examples.

  • For practice, you can create some input types to check output. Then you will understand more.
  • Jaldi se implement karoooooo abhiii😀😍

Important Note: Want to download the full HTML course as a PDF? Click here to save it locally!

Leave a Comment