Techoceanhub logo

Form structure and attributes in HTML

In HTML (Hypertext Markup Language), you can create the structure of a web page using various elements and define their attributes to specify additional information or behavior. Here’s an example of how to create a basic form structure with attributes:

<!DOCTYPE html>
<html>
<head>
  <title>Sample Form</title>
</head>
<body>
  <form action="/submit" method="POST">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required>

    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>

    <label for="message">Message:</label>
    <textarea id="message" name="message" required></textarea>

    <input type="submit" value="Submit">
  </form>
</body>
</html>

Let’s break down the structure and attributes used in this form:

  1. The <form> element creates a container for all form-related elements.
    • The action attribute specifies the URL or endpoint where the form data will be submitted.
    • The method attribute defines the HTTP method to be used when submitting the form, usually “GET” or “POST”.
  2. Inside the <form> element, we have several form controls:
    • The <label> element associates a text label with an input control.
      • The for attribute specifies the corresponding input control using its id.
    • The <input> element represents an input control, such as a text field or email field.
      • The type attribute specifies the type of input control, like “text” or “email”.
      • The id attribute uniquely identifies the input control for associating it with a label.
      • The name attribute provides a name for the input control, which is used when submitting the form.
      • The required attribute indicates that the field must be filled out before submitting the form.
    • The <textarea> element creates a multiline text input field.
      • The id and name attributes are similar to those used in the <input> element.
      • The required attribute makes the field mandatory.
    • The <input> element with type="submit" creates a submit button.
      • The value attribute sets the text displayed on the button.

Note that this is just a basic example, and there are many more attributes and form controls available in HTML. You can customize and extend the form structure based on your requirements.

Share:

Categories

Archives

Related Posts

Array Destructuring

Array Destructuring Array destructuring is a powerful syntax introduced in ES6 that allows you to unpack elements from an array

Read More »

Explore our Affiliated partner links

hostgator website plan

Hostgator

Best Website hosting plans & Best for 24/7 support.

hostinger webhosting plan

Hostinger

Reasonable website hosting packages for small business & 24/7 Email support

Elementor pro

Design Worpdress website quickly using Elementor Builder and AI

buy elementor website templates

Buy Elementor Website Template

Buy ready made Elementor Website Template from us & Get Free Elementor pro licence for 1 year .