Open In App

HTML input Tag

Improve
Improve
Like Article
Like
Save
Share
Report

The HTML input Tag is the place where a user can enter data. The input tag is used within < form> element to declare input controls that allow users to input data. The default value accepted by the <input> Tag is text.

An input field can be of various types depending upon the attribute type. The Input tag is an empty element that only contains attributes. For defining labels for the input element, < label> can be used.

Note: The <input> Tag supports the Global Attributes & the Event Attributes in HTML.

Syntax

<input type = "value" ... />

<input> type Attribute

Attributes

Attributes

Descriptions

type

It is used to specify the type of the input element. Its default value is text.

value

It is used to specify the value of the input element.

placeholder

Placeholder attribute is used to specify hint that describes the expected value of an input field.

name

It is used to specify the name of the input element.

alt

It is used to provide alternate text for the user, if they cannot view the image.

autofocus

It specifies that an element should automatically get focus when the page loads.

checked

It specifies that an element should be pre-selected (checked) when the page loads.

disabled

The disabled attribute specifies that the element should be disabled

form

The form attribute is used to specify one or more forms to which the <input> element belongs to. 

max

It is used to specify the maximum value for an < input > element.

required

It specifies that an input field must be filled out before submitting the form. 

readonly

It specifies that an input field is read-only. A read-only input field cannot be modified.

accept

It is used to specifies the types of files that the server accepts.

align

It is used to specifies the alignment of an image input.

autocomplete

It s used to specifies whether an <input> element should have autocomplete enabled

dirname

It is used to specifies that the text direction will be submitted.

formaction

It is used to specifies the URL of the file that will process the input control when the form is submitted

formenctype

It is used to specifies how the form-data should be encoded when submitting it to the server

formmethod

It is used to defines the HTTP method for sending data to the action URL

formnovalidate

It is used to defines that form elements should not be validated when submitted

formtarget

It is used to specifies where to display the response that is received after submitting the form

height

It is used to specifies the height of an <input> element

list

It is used to refers to a <datalist> element that contains pre-defined options for an <input> element

maxlength

It is used to specifies the maximum number of characters allowed in an <input> element

min

It is used to specifies a minimum value for an <input> element

multiple

It is used to specifies that a user can enter more than one value in an <input> element

pattern

It is used to specifies a regular expression that an <input> element’s value is checked against

size

It is used to specifies the width, in characters, of an <input> element

src

It is used to specifies the URL of the image to use as a submit button

step

It is used to specifies the legal number intervals for an input field

width

It is used to specifies the width of an <input> element (only Ifor type=”image”)

Example 1: In this example, we will see the implementation of input tag Using “type” attribute. 

html




<!DOCTYPE html>
<html lang="en">
<style>
    body {
        text-align: center;
    }
</style>
 
<body>
    <h1 style="color: green;">
      GeeksForGeeks
      </h1>
 
    <form>
        <label>Name:</label>
        <input type="text" name="name" value="">
          <br><br>
 
        <label>E-mail:</label>
        <input type="email" name="emailaddress">
          <br><br>
 
        <label>Password: </label>
        <input type="password" name="password">
          <br><br>
 
        <input type="submit">
    </form>
</body>
 
</html>


Output: 

Screenshot-2023-12-15-103731

Example 2: In this example, we will see the implementation of input tag Using “value” attribute. 

html




<!DOCTYPE html>
<html>
 
<body>
    <h1>GeeksForGeeks</h1>
    <form>
 
        <label> Name: </label>
        <input type="text" name="name1" value="Rahul">
        <br>
        <br>
        <input type="submit" value="Submit form">
 
    </form>
</body>
 
</html>


Output:

Supported Browsers

  • Google Chrome 15 
  • Edge 12 and above
  • Firefox 1 and above
  • Opera 14 and above
  • Safari 6 and above


Last Updated : 20 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads