Forms & Inputs

HTML <input> Tag

The <input> tag specifies an input field where the user can enter data.

Definition and Usage

The <input> tag specifies an input field where the user can enter data.

Standard Syntax:<input>

Interactive ExampleRunnable

HTML <input> Example

html
Try it Yourself
Live code demonstration for the <input> tag. Click "Try it Yourself" to edit and experiment in real time.
<div style="font-family: system-ui, sans-serif; padding: 16px; background: #ffffff; border-radius: 8px; border: 1px solid #e2e8f0; color: #0f172a;">
<form 
    action="/action_page.php">

 
    <label for="fname">First name:</label>
  <input type="text" 
    id="fname" name="fname"><br><br>

     
    <label for="lname">Last name:</label>
  <input type="text" 
    id="lname" name="lname"><br><br>

     
    <input type="submit" value="Submit">

    </form>
</div>

Attributes for <input>

32 Supported Attributes
AttributeValuesDefaultDescription
acceptfile_extension audio/* video/* image/* media_typenoneSpecifies a filter for what file types the user can pick from the file input dialog box (only for type="file")
alttextnoneSpecifies an alternate text for images (only for type="image")
autocompleteon offnoneSpecifies whether an <input> element should have autocomplete enabled
autofocusautofocusnoneSpecifies that an <input> element should automatically get focus when the page loads
checkedcheckednoneSpecifies that an <input> element should be pre-selected when the page loads (for type="checkbox" or type="radio")
dirnameinputname.dirnoneSpecifies that the text direction will be submitted
disableddisablednoneSpecifies that an <input> element should be disabled
formform_idnoneSpecifies the form the <input> element belongs to
formactionURLnoneSpecifies the URL of the file that will process the input control when the form is submitted (for type="submit" and type="image")
formenctypeapplication/x-www-form-urlencoded multipart/form-data text/plainnoneSpecifies how the form-data should be encoded when submitting it to the server (for type="submit" and type="image")
formmethodgetpostnoneDefines the HTTP method for sending data to the action URL (for type="submit" and type="image")
formnovalidateformnovalidatenoneDefines that form elements should not be validated when submitted
formtarget_blank _self _parent _top framenamenoneSpecifies where to display the response that is received after submitting the form (for type="submit" and type="image")
heightpixelsnoneSpecifies the height of an <input> element (only for type="image")
listdatalist_idnoneRefers to a <datalist> element that contains pre-defined options for an <input> element
maxnumber datenoneSpecifies the maximum value for an <input> element
maxlengthnumbernoneSpecifies the maximum number of characters allowed in an <input> element
minnumber datenoneSpecifies a minimum value for an <input> element
minlengthnumbernoneSpecifies the minimum number of characters required in an <input> element
multiplemultiplenoneSpecifies that a user can enter more than one value in an <input> element
nametextnoneSpecifies the name of an <input> element
patternregexpnoneSpecifies a regular expression that an <input> element's value is checked against
placeholdertextnoneSpecifies a short hint that describes the expected value of an <input> element
popovertargetelement_idnoneSpecifies which popover element to invoke (only for type="button")
popovertargetactionhideshowtogglenoneSpecifies what happens to the popover element when you click the button (only for type="button")
readonlyreadonlynoneSpecifies that an input field is read-only
requiredrequirednoneSpecifies that an input field must be filled out before submitting the form
sizenumbernoneSpecifies the width, in characters, of an <input> element
srcURLnoneSpecifies the URL of the image to use as a submit button (only for type="image")
stepnumberanynoneSpecifies the interval between legal numbers in an input field
typebutton checkbox color date datetime-local email file hidden image month number password radio range reset search submit tel text time url weeknoneSpecifies the type <input> element to display
widthpixelsnoneSpecifies the width of an <input> element (only for type="image")
Global Attributes

The <input> tag also supports the standard global attributes in HTML, including class, id, style, title, hidden, and data-*.

HTML Global Attributes Reference →
Event Attributes

The <input> tag supports event attributes in HTML, such as onclick, onmouseover, onfocus, and more.

HTML Event Attributes Reference →

Browser Compatibility

ChromeEdgeFirefoxSafariOpera

More Tags in Forms & Inputs

View All 123Tags →