
HTML input Tag
The <input>
tag is an HTML element used to create various types of input fields on a web page. It is a self-closing tag and does not require a closing tag.
Here’s an example of how the <input>
tag is used:
<!DOCTYPE html>
<html>
<head>
<title>My Form</title>
</head>
<body>
<form> <label for="name">Name:</label> <input type="text" id="name" name="name" placeholder="Enter your name">
<label for="email">Email:</label> <input type="email" id="email" name="email" placeholder="Enter your email address"> <input type="submit" value="Submit"> </form>
</body>
</html>
In this example, we have a simple form containing two input fields and a submit button. Let’s break down the code:
- The
<form>
tag is used to group the input elements together to create a form. - The
<label>
tags provide a text label for each input field, using thefor
attribute to associate the label with its corresponding input field using theid
attribute. - The
<input>
tags define the actual input fields. Thetype
attribute determines the type of input field to be created. In this example, we have usedtype="text"
for a text input field andtype="email"
for an email input field. Theid
andname
attributes uniquely identify the input field and are used for various purposes such as JavaScript access and form submission. - The
placeholder
attribute provides a hint or example text that is displayed within the input field to guide the user.
Finally, the submit button is created using <input type="submit">
with the value
attribute specifying the text displayed on the button.
The <input>
tag supports various other types such as password
, checkbox
, radio
, number
, and more. Each type has specific attributes and behaviors associated with it.
Remember to properly validate and process the data submitted through input fields on the server-side to ensure security and integrity of your application.