HTML disabled Attribute
Definition and Usage
The disabled attribute is a boolean attribute.
When present, it specifies that the element should be disabled.
A disabled element is unusable.
The disabled attribute can be set to keep a user from using the element until some other condition has been met (like selecting a checkbox, etc.). Then, a JavaScript could remove the disabled value, and make the element usable.
Applies to
The disabled attribute can be used on the following elements:
Elements | Attribute |
---|---|
<button> | disabled |
<fieldset> | disabled |
<input> | disabled |
<keygen> | disabled |
<optgroup> | disabled |
<option> | disabled |
<select> | disabled |
<textarea> | disabled |
Examples
Button Example
A disabled button:
Fieldset Example
Disable a group of related form elements:
<legend>Personalia:</legend>
Name: <input type="text"><br>
Email: <input type="text"><br>
Date of birth: <input type="text">
</fieldset>
Input Example
An HTML form with a disabled input field:
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname" disabled><br>
<input type="submit" value="Submit">
</form>
Keygen Example
A disabled <keygen> element:
Username: <input type="text" name="usr_name">
Encryption: <keygen name="security" disabled>
<input type="submit">
</form>
Optgroup Example
A disabled option-group:
<optgroup label="German Cars" disabled>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</optgroup>
</select>
Option Example
A drop-down list with one disabled option:
<option value="volvo" disabled>Volvo</option>
<option value="saab">Saab</option>
<option value="vw">VW</option>
<option value="audi">Audi</option>
</select>
Select Example
A disabled drop-down list:
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
Textarea Example
A disabled text area:
At subhodaya.com you will learn how to make a website. We offer free tutorials in all web development technologies.
</textarea>
Browser Support
The disabled
attribute has the following browser support for each element:
Element | |||||
---|---|---|---|---|---|
button | Yes | Yes | Yes | Yes | Yes |
fieldset | Yes | Not supported | Yes | 7.0 | Yes |
input | 1.0 | 6.0 | 1.0 | 1.0 | 1.0 |
keygen | Yes | Not supported | Yes | 6.0 | Yes |
optgroup | 1.0 | 8.0 | Yes | Yes | Yes |
option | 1.0 | 8.0 | 1.0 | Yes | Yes |
select | Yes | Yes | Yes | Yes | Yes |
textarea | Yes | Yes | Yes | Yes | Yes |