Old Elements
New Elements
<label for="inputID">Label: </label>
<input id="inputID" name="inputName" type="text" />
or
<label>Label: <input name="inputName" type="text" /></label>
The value of the for attribute should match the value of the input's id attribute
Click on the label to activate the form element:
<label for="name">Name: </label>
<input id="name" name="inputName"
placeholder="placeholder text"
pattern="\w{6,9}"
required
autofocus
type="text"/>
Note that the following CSS is used in our live examples:
input:focus:invalid { background-color: lightPink;}
input:valid { background-color:lightGreen }
input:required {border: 2px solid red;}
input:optional {border: 2px solid green;}
<label for="inputID">Label: </label>
<input id="inputID" name="inputName"
placeholder="placeholder text"
pattern="\w{6,9}"
required
autofocus
type="text"/>
<label for="inputID">Label: </label>
<input id="inputID" name="inputName"
placeholder="\w{6,9}"
pattern="\w{6,9}"
required
autofocus
type="text"/>
<label for="inputID">Label: </label>
<input id="inputID" name="inputName"
placeholder="placeholder text"
pattern="\w{6,9}"
required
type="text"/>
input[required] {border: 1px dashed #f00;} or
input:required {border: 1px dashed #f00;}
FF: "Please fill out this field"
<label for="inputID">Label: </label>
<input id="inputID" name="inputName"
placeholder="placeholder text"
pattern="\w{6,9}"
required
autofocus
type="text"/>
only one element can have the autofocus attribute
$('[autofocus]').last().focus();
<label for="inputID">Label: </label>
<input id="inputID" name="inputName"
placeholder="placeholder text"
pattern="\w{6,9}"
required
autofocus
type="text" />
<label for="inputID">Label: </label>
<input id="inputID" name="inputName"
placeholder="placeholder text"
pattern="\w{6,9}"
required
autofocus
form="notMyParentForm"
type="text" />
Note: form="" disassociates a form element from its parent form.
<input name="color" type="color" />
<input id="color" name="color"
type="color"
placeholder="#FFFFFF"
pattern="#[0-9A-Fa-f]{6}"
required />
<input name="website" type="url" />
<input id="website" name="url" type="url" placeholder="http://www.domain.com" pattern="(http|https|ftp)\:\/\/[a-zA-Z0-9\-\.\/]*"/>
different dynamic keyboards displayed based on input type.
<input name="telephone" type="tel" />
Custom Keyboard. No validation.
<input
id="phone" name="phone" type="tel"
placeholder="415-555-1212"
pattern="\d{3}\-\d{3}\-\d{4}"/>
<input name="address" type="email" />
Keyboard changes & validation!
<input id="email" name="email" type="email" placeholder="you@domain.com" multiple />
<input name="n" type="number"/>
'number' specific attributes:
<input id="nickels" type="number" placeholder="0, 5, 10 …" pattern="[0-9]*[05]" min="0" max="1000" step="5" />
<input id="range" name="range" type="range" placeholder="0 to 10" pattern="[0-9]|10" min="0" max="10" step="1"/>Current Value:
<input id="range" name="range" type="range" min="0" max="100" step="5"/>Current Value:
<input id="search" name="search" type="search" placeholder="search terms"/>
| date | 2010-11-03 | |
| datetime | 2010-11-03 19:00 | |
| datetime-local | 2010-11-03 19:00 | |
| month | 2010-11 | |
| time | 19:00 | |
| week | 2010-W44 |
<input id="DOB" name="DOB"
type="date"
placeholder="YYYY-MM-DD"
pattern="\d{4}\-\d{2}\-\d{2}"
min="1900-01-01" />
<input name="time" id="time" type="time" min="09:00" max="17:00" step="900" placeholder="12:00" required />
var validityObject = document.getElementById['form_control'].validity;
function validate() {
var input = document.getElementById('b');
var validityState_object = input.validity;
if(validityState_object.valueMissing) {
input.setCustomValidity('Please set an age (required)');
} else if (input.rangeUnderflow) {
input.setCustomValidity('Your value is too low');
} else if (input.rangeOverflow) {
input.setCustomValidity('Your value is too high');
} else {
input.setCustomValidity('');
}
}
::-webkit-validation-bubble {}
::-webkit-validation-bubble-arrow-clipper {}
::-webkit-validation-bubble-arrow {}
::-webkit-validation-bubble-message {}
<label for="url">Web Address: </label> <input id="url" type="url" name="url1" placeholder="www.domain.com" required list="datalist1" /> <datalist id="datalist1"> <option value="http://www.standardista.com" /> <option value="http://www.oreilly.com" /> <option value="http://www.evotech.net" /> </datalist>
<meter value=75 min=0 max=100 >75% full</meter>
Gas tank:
<progress>loading...</progress>
Please wait:
<progress value="75" max="100">75% complete</progress>
Download is:
<output>
<meter value=90 min=0 max=100 low=20 high=98>75%</meter>
Gas tank:
<meter value=75 min=0 max=100 low=20 high=98>75%</meter>
Grades:
<meter min=50 max=200 low=90 high=119 optimum=100></meter>
Blood Pressure:
<input type="text" x-webkit-speech />