HTML | input Tag

In HTML, the input field can be specified using where a user can enter data. The input tag is used within < form> element to declare input controls that allow users to input data. An input field can be of various types depending upon the attribute type. The is an empty element which only contains attributes. For defining labels for the input element, < label> can be used.

Attributes:

  • type:The type attribute is used to specify the type of the input element. Its default value is text.
  • value:The value attribute 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: The name attribute is used to specify the name of the input element.
  • alt:The alt attribute is used to provide alternate text for the user, if they cannot view the image.
  • autofocus:Autofocus attribute specifies that an element should automatically get focus when the page loads.
  • checked:The checked attribute specifies that an element should be pre-selected (checked) when the page loads. The checked attribute can be used with < input type=”checkbox” > and < input type=”radio” >.
  • disabled:The disabled attribute specifies that the element should be disabled. The disabled attribute can be set to keep a user from using the < input > element until some other condition has been met.
  • form:The form attribute is used to specify one or more forms to which the <input> element belongs to.

  • max:The max attribute is used to specify the maximum value for an < input > element.
  • required:The required attribute specifies that an input field must be filled out before submitting the form.
  • readonly:The readonly attribute specifies that an input field is read-only. A read-only input field cannot be modified. A form will still submit an input field that is readonly, but will not submit an input field that is disabled.
  • accept: This property is used to specifies the types of files that the server accepts.
  • align: This property is used to specifies the alignment of an image input.
  • autocomplete: This property is used to specifies whether an <input> element should have autocomplete enabled.
  • dirname: This property is used to specifies that the text direction will be submitted.
  • formaction: This property is used to specifies the URL of the file that will process the input control when the form is submitted (for type=”submit” and type=”image”)
  • formenctype: This property is used to specifies how the form-data should be encoded when submitting it to the server (for type=”submit” and type=”image”)
  • formenctype: This property is used to specifies how the form-data should be encoded when submitting it to the server (for type=”submit” and type=”image”)
  • formmethod: This property is used to defines the HTTP method for sending data to the action URL (for type=”submit” and type=”image”)
  • formnovalidate: This property is used to defines that form elements should not be validated when submitted
  • formtargetThis property is used to specifies where to display the response that is received after submitting the form (for type=”submit” and type=”image”)
  • height: This property is used to specifies the height of an <input> element (only for type=”image”)
  • list: This property is used to refers to a <datalist> element that contains pre-defined options for an <input> element
  • maxlength: This property is used to specifies the maximum number of characters allowed in an <input> element
  • min: This property is used to specifies a minimum value for an <input> element
  • multiple: This property is used to specifies that a user can enter more than one value in an <input> element
  • pattern: This property is used to specifies a regular expression that an <input> element’s value is checked against
  • size: This property is used to specifies the width, in characters, of an <input> element
  • src: This property is used to specifies the URL of the image to use as a submit button (only for type=”image”)
  • step: This property is used to specifies the legal number intervals for an input field
  • width: This property is used to specifies the width of an <input> element (only for type=”image”)

Example-1: Using “type” attribute.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1>GeeksForGeeks</h1>
        <p>
            The type email defines 
          a field for email address and 
          type submit defines a submit button.
        </p>
        <form>
  
            <label>E-mail:</label>
            <input type="email"
                   name="emailaddress">
            <br>
            <br>
            <input type="submit">
  
        </form>
    </center>
</body>
  
</html>

chevron_right


Output:

Example-2: Using “value” attribute.

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

Supported Browsers:

  • Google Chrome
  • Internet Explore
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.