HTML <input> tag

The <input> tag is used to display an input field in a form and get data from the user. Input fields include textboxes, buttons, radio buttons, checkboxes, and more.

NOTE: The <input> tag has no end tag.

Attributes

Attribute Description Possible values
accept Specifies a list of file types that can be uploaded using the file upload input element. MIMEtypes
align Deprecated. Sets the alignment of an image in a form left, right, top, middle, bottom
alt Specifies alternative text to be displayed if the image in a form does not load altText
checked Specifies that the radio or checkbox in a form should be automatically selected when the page loads checked
disabled Specifies that an input field will be disabled (will be grayed out and the user will not be able to edit it) disabled
maxlength Specifies the maximum number of characters that a text field can have maxCharacters
name Sets the name of an input field nameOfField
readonly Specifies that a text field is read-only, meaning you can't change its content but only read what's already there readonly
size Sets the width of an input field numericValue
src Specifies the location of the image (when you're including an image in a form) locationOfImg
type Specifies what input field to display button, checkbox, file, hidden, image, password, radio, reset, submit, text
value Specifies text to be displayed by default within certain form elements.
NOTE: If the type attribute is set with the value "radio" or "checkbox" then this attribute is required!
textToDisplay

Standard attributes

accesskey, class, dir, id, lang, style, tabindex, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

onfocus, onblur, onselect, onchange, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

For more information on event attributes, check out our HTML event attributes reference page.

Example

<form> First name: <input type="text" name="name" /><br /> Last name: <input type="text" name="lname" /><br /> E-mail: <input type="text" name="email" /><br /> Choose a password: <input type="password" name="pw1" /><br /> Enter password again: <input type="password" name="pw1" /><br /> Subscribe to our newsletter? <input type="radio" name="newsletter" value="Yes" />Yes <input type="radio" name="newsletter" value="No" />No <input type="reset" value="Reset" /> <input type="submit" value="Submit" /> </form>
Output:
First name:
Last name:
E-mail:
Choose a password:
Enter password again:
Subscribe to our newsletter? Yes No

Tips & notes

Use the <label> tag to set the text of input elements in a form.

Use CSS to style input elements in many ways like setting a border, font size and color, background color, padding, and much more.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation