HTML and CSS Reference
In-Depth Information
Text Fields
One of the primary elements used to obtain text from users is the
<input>
element. The
<input>
element uses the
type
attribute to define what type of information is to be cap-
tured within the control. The most popular
type
attribute value is
text
, which denotes a
single line of text input.
Along with setting a
type
attribute, it is best practice to give an
<input>
element a
name
attribute as well. The
name
attribute value is used as the name of the control and is
submitted along with the input data to the server (see
Figure 10.1
)
.
1.
<input type="text" name="username">
Figure 10.1
A self-contained text input created with the
<input>
element
The
<input>
element is self-contained, meaning it uses only one tag and it does not wrap
any other content. The value of the element is provided by its attributes and their corres-
ponding values.
Originally, the only two text-based
type
attribute values were
text
and
password
(for
password inputs); however, HTML5 brought along a handful of new
type
attribute val-
ues. These values were added to provide clearer semantic meaning for inputs as well as to
provide better controls for users. Should a browser not understand one of these HTML5
type
attribute values, it will automatically fall back to the
text
attribute value. Below is
a list of the new HTML5 input types.
•
color
•
date
•
datetime
•
email
•
month
•
number
•
range
•
search
•
tel
Search WWH ::
Custom Search