w3schools    w3Schools
Search W3Schools :
   
HOME HTML CSS XML JAVASCRIPT ASP PHP SQL MORE...   References Examples Forum About
ADVERTISEMENTS

XML Certification
Download XML editor
Custom Programming
 
Table of contents
HTML Reference
HTML by Alphabet
HTML by Function
HTML Attributes
HTML Events
HTML Colornames
HTML Character Sets
HTML ASCII
HTML ISO-8859-1
HTML Symbols
HTML URL Encode
HTML Lang Codes
HTTP Messages

HTML Tags
<!-->
<!DOCTYPE>
<a>
<abbr>
<acronym>
<address>
<applet>
<area>
<b>
<base>
<basefont>
<bdo>
<big>
<blockquote>
<body>
<br>
<button>
<caption>
<center>
<cite>
<code>
<col>
<colgroup>
<dd>
<del>
<dfn>
<dir>
<div>
<dl>
<dt>
<em>
<fieldset>
<font>
<form>
<frame>
<frameset>
<head>
<h1> - <h6>
<hr>
<html>
<i>
<iframe>
<img>
<input>
<ins>
<kbd>
<label>
<legend>
<li>
<link>
<map>
<menu>
<meta>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<p>
<param>
<pre>
<q>
<s>
<samp>
<script>
<select>
<small>
<span>
<strike>
<strong>
<style>
<sub>
<sup>
<table>
<tbody>
<td>
<textarea>
<tfoot>
<th>
<thead>
<title>
<tr>
<tt>
<u>
<ul>
<var>

Selected Reading
Web Statistics
Web Glossary
Web Hosting
Web Quality

W3Schools Tutorials
W3Schools Forum

Helping W3Schools

 

HTML <input> tag


Example

A simple HTML form with two input fields and one submit button:

<form action="form_action.asp" method="get">
  First name: <input type="text" name="fname" /><br />
  Last name: <input type="text" name="lname" /><br />
  <input type="submit" value="Submit" />
</form>

Try it yourself!  (more examples at the bottom of this page)


Definition and Usage

The <input> tag is used to select user information.

An input field can vary in many ways, depending on the type attribute. An input field can be a text field, a checkbox, a password field, a radio button, a button, and more.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The <input> tag is supported in all major browsers.


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

Tip: Use the <label> tag to define labels for input elements.


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 top
texttop
middle
absmiddle
baseline
bottom
absbottom
Deprecated. Use styles instead.
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 an input field.

Note: Only used with type="text" or type="password"

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" or type="password"

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, tabindex, accesskey

For a full description, go to Standard Attributes.

Event Attributes

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

Password fields
How to create a password field on an HTML page.

Create a button
How to create a button. On the button you can define your own text.

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.



DreamTemplate



diploma   

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 JavaScript Certificate is for developers who want to document their knowledge of JavaScript and the HTML DOM.

The XML Certificate is for developers who want to document their knowledge of XML, XML DOM and XSLT.

The ASP Certificate is for developers who want to document their knowledge of ASP, SQL, and ADO.

The PHP Certificate is for developers who want to document their knowledge of PHP and SQL (MySQL).


 
WEB HOSTING
ASP.NET Web Hosting
ASP.NET
Web Hosting
$15 Domain Name
Registration
Save $20 / year!
Buy UK Domain Names
Register Domain Names
Cheap Domain Names
Cheap Web Hosting
Best Web Hosting
PHP MySQL Hosting
Top 10 Web Hosting
UK Reseller Hosting
Web Hosting
FREE Web Hosting
WEB BUILDING
Website Templates
Flash Templates
Website Builder
Internet Business Opportunity
Custom Programming
FREE Trial or Demo
Web Content Manager
Forms,Web Alerts,RSS
Download XML editor
FREE Flash Website
FREE Web Templates
EDUCATION
US Web Design Schools
HTML Certification
JavaScript Certification
XML Certification
PHP Certification
ASP Certification
Home HOME or Top of Page Validate   Validate   W3C-WAI level A conformance icon Printer Friendly  Printer Friendly

W3Schools is for training only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user.
While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright 1999-2009 by Refsnes Data. All Rights Reserved.