HTML <input> tag
Definition and Usage
The <input> tag defines the start of an input field where the user can
enter data.
Differences Between HTML and XHTML
In HTML the <input> tag has no end tag.
In XHTML the <input> tag must be properly closed.
Tips and Notes
Note: The input element is empty, it contains attributes only.
Tip: Use the label element to define a label to a
form control.
Example
| Source |
Output |
<form
action="form_action.asp"
method="get">
First name:
<input type="text" name="fname" value="Mickey"
/>
<br />
Last name:
<input type="text" name="lname" value="Mouse"
/>
<br />
<input type="submit" value="Submit" />
</form>
<p>
If you click the "Submit" button, you will send your input to a new page
called form_action.asp.
</p> |
If you click the "Submit" button, you will send your input to a new page called
form_action.asp.
|
Optional Attributes
DTD indicates in which DTD the attribute is
allowed. S=Strict, T=Transitional, and F=Frameset.
| Attribute |
Value |
Description |
DTD |
| accept |
list_of_mime_types |
A comma-separated list of MIME types that indicates the
MIME type of the file transfer. Note: Only
used with type="file" |
STF |
| align |
left
right
top
texttop
middle
absmiddle
baseline
bottom
absbottom |
Defines the alignment of text following the image. Note: Only used with type="image" |
TF |
| alt |
text |
Defines an alternate text for the image. Note: Only used with type="image" |
STF |
| checked |
checked |
Indicates that the input element should be checked when
it first loads. Note: Used with type="checkbox" and type="radio" |
STF |
| disabled |
disabled |
Disables the input element when it first loads so that the
user can not write text in it, or select it.
Note: Cannot be used with type="hidden" |
STF |
| maxlength |
number |
Defines
the maximum number of characters allowed in a text field. Note:
Only used with type="text" |
STF |
| name |
field_name |
Defines a unique name for the input element. Note:
This attribute is required with type="button", type="checkbox", type="file",
type="hidden", type="image", type="password", type="text", and type="radio" |
STF |
| readonly |
readonly |
Indicates that the value of this field cannot be modified.
Note: Only used with type="text" |
STF |
| size |
number_of_char |
Defines the size of the input element. Note: Cannot be used with type="hidden" |
STF |
| src |
URL |
Defines the URL of the image to display. Note: Only used with
type="image" |
STF |
| type |
button
checkbox
file
hidden
image
password
radio
reset
submit
text |
Indicates the type of the input element. The default value is
"text"
Note: This is not a required attribute, but we think you should
include it. If omitted, IE 5.5 will still display a text field, but
Netscape 4.7 will not.
|
STF |
| value |
value |
For buttons, reset buttons and submit buttons:
Defines the text on the button. For image buttons: Defines the
symbolic result of the field passed to a script.
For checkboxes and radio buttons: Defines the result of the input
element when clicked. The result is sent to the form's action URL.
For hidden, password, and text fields: Defines the default value
of the element.
Note: Cannot be used with type="file"
Note: This attribute is required with type="checkbox" and
type="radio"
|
STF |
Standard Attributes
| id, class, title, style, dir, lang, xml:lang |
For a full description, go to Standard
Attributes.
Event Attributes
| tabindex, accesskey, onfocus, onblur, onselect, onchange, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup |
For a full description, go to Event
Attributes.
Try-It-Yourself Demos
Text fields
How to create text fields on an HTML page. A user can
write text in a text field.
Password fields
How to create a password field on an HTML page.
Checkboxes
How to create check-boxes on an HTML page. A user can select or unselect a checkbox.
Radiobuttons
How to create radio-buttons on an HTML page.
Create a button
How to create a button. On the button you can define your own text.
Form with input fields and a submit button
How to add a form to a page. The form contains two input fields and a submit
button.
Form with checkboxes
This form contains two checkboxes, and a submit button.
Form with radiobuttons
This form contains two radio buttons, and a submit button.
Whether you're new to XML or already an advanced user, the user-friendly views
and powerful entry helpers, wizards, and debuggers in XMLSpy are designed to
meet your XML and Web services development needs from start to finish.
- XML editor
- Graphical XML Schema / DTD editors
- XSLT 1.0/2.0 editor, debugger, profiler
- XQuery editor, debugger, profiler
- Support for Office Open XML (OOXML)
- Graphical WSDL editor & SOAP debugger
- Java, C#, C++ code generation
- And much more!
Download a free 30-day trial today!
Click to see a demo!
Learn what’s new in v2008
 |
|
Get Your Diploma!
W3Schools' Online Certification Program is the perfect solution for busy
professionals who need to balance work, family, and career building.
The HTML Certificate is for developers who want to document their knowledge of HTML, XHTML, and CSS.
The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.
|
|