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