HTML | disabled Attribute

The disabled attribute in HTML indicates whether the element is disabled or not. If this attribute is set, the element is disabled. Disabled attribute are usually drawn with grayed-out text. If the element is disabled, it does not respond to user actions, it cannot be focused. It is a boolean attribute.

Usage: It can be used on the following elements: <button>, <input>, <option>, <select>, <textarea>, <feildset> and <optgroup>.

  • <button>: When the disabled attribute is present, it specifies that the button is disabled. A disabled button is unusable and un-clickable.
    Syntax:

    <button disabled></button>
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <title>HTML disabled Attribute</title
        </head
        <body style = "text-align:center">    
            <h1 style = "color: green;">GeeksforGeeks</h1>
            <h2>HTML disabled Attribute</h2>
              
            <!--A disabled button-->
            <button type="button" disabled>Click Me!</button>
        </body
    </html>    

    chevron_right

    
    

    Output:
    button



    Supported Browsers: The browser supported by disabled attribute for <button> element are listed below:

    • Apple Safari
    • Google Chrome
    • Firefox
    • Opera
    • Internet Explorer
  • <input>: When the disabled attribute is present, it specifies that the input is disabled. A disabled inpit is unusable and un-clickable.
    Syntax:

    <input disabled>
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <title>HTML disabled Attribute</title
        </head
        <body style = "text-align:center">    
            <h1 style = "color: green;">GeeksforGeeks</h1>
            <h2>HTML disabled Attribute</h2>
      
            <!--A disabled input-->
            <label>Input:
                <input type="text" name="value" value = "This input 
                       field is disabled" disabled>
            </label>
        </body
    </html>    
      
      
         

    chevron_right

    
    

    Output:
    input

    Supported Browsers: The browser supported by disabled attribute for <input> element are listed below:

    • Apple Safari 1.0
    • Google Chrome 1.0
    • Firefox 1.0
    • Opera 1.0
    • Internet Explorer 6.0
  • <option>: When the disabled attribute is present, it specifies that the option field is disabled. A disabled option is unusable and un-clickable.
    Syntax:

    <option disabled>option value...</option>
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <title>HTML disabled Attribute</title
        </head
        <body style = "text-align:center">    
            <h1 style = "color: green;">GeeksforGeeks</h1>
            <h2>HTML disabled Attribute</h2>
      
            <!--A disabled input-->
            <p>Volvo is disabled.</p>
            <select>
                 <option value="volvo" disabled>Volvo</option>
                 <option value="saab">Saab</option>
                 <option value="vw">VW</option>
                 <option value="audi">Audi</option>
            </select><br>
              
        </body
    </html>    

    chevron_right

    
    

    Output:
    option

    Supported Browsers: The browser supported by disabled attribute for <option> element are listed below:

    • Apple Safari
    • Google Chrome 1.0
    • Firefox 1.0
    • Opera
    • Internet Explorer 8.0
  • <select>: When the disabled attribute is present, it specifies that the select field is disabled. A disabled select is unusable and un-clickable.
    Syntax:



    <select disabled>option value...</select>
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <title>HTML disabled Attribute</title
        </head
        <body style = "text-align:center">    
            <h1 style = "color: green;">GeeksforGeeks</h1>
            <h2>HTML disabled Attribute</h2>
      
            <!--A disabled input-->
            <p>This select field is disabled.</p>
            <select disabled>
                 <option value="binary">Binary Search</option>
                 <option value="linear">Linear Search</option>
                 <option value="interpolation">Interpolation Search</option>
            </select>
        </body
    </html>    

    chevron_right

    
    

    Output:
    select

    Supported Browsers: The browser supported by disabled attribute for <select> element are listed below:

    • Apple Safari
    • Google Chrome
    • Firefox
    • Opera
    • Internet Explorer
  • <textarea>: When the disabled attribute is present, it specifies that the textarea field is disabled. A disabled textarea is unusable and un-clickable.
    Syntax:

    <textarea disabled>text content...</textarea>
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <title>HTML disabled Attribute</title
        </head
        <body style = "text-align:center">    
            <h1 style = "color: green;">GeeksforGeeks</h1>
            <h2>HTML disabled Attribute</h2>
      
            <!--A disabled textarea-->
            <textarea disabled>
                This textarea field is disabled.
            </textarea>
        </body
    </html>    

    chevron_right

    
    

    Output:
    textarea

    Supported Browsers: The browser supported by disabled attribute for <textarea> element are listed below:

    • Apple Safari
    • Google Chrome
    • Firefox
    • Opera
    • Internet Explorer
  • <fieldset>: When the disabled attribute is present, it specifies that the fieldset is disabled. A disabled fieldset is unusable and un-clickable.
    Syntax:

    <fieldset disabled>fieldset content...</fieldset>
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <title>HTML disabled Attribute</title
        </head
        <body style = "text-align:center">    
            <h1 style = "color: green;">GeeksforGeeks</h1>
            <h2>HTML disabled Attribute</h2>
      
            <!--A disabled fieldset-->
            <p>This field set is disabled.</p>
            <fieldset disabled>
              Name: <input type="text"><br>
            </fieldset>
        </body
    </html>    

    chevron_right

    
    

    Output:
    fieldset



    Supported Browsers: The browser supported by disabled attribute for <fieldset> element are listed below:

    • Apple Safari 8.0
    • Google Chrome
    • Firefox
    • Opera
    • Internet Explorer Not supported
  • <optgroup>: When the disabled attribute is present, it specifies that the optgroup is disabled. A disabled optgroup is unusable and un-clickable.
    Syntax:

    <optgroup disabled>option value...</optgroup>
    

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html> 
    <html
        <head
            <title>HTML disabled Attribute</title
        </head
        <body style = "text-align:center">    
            <h1 style = "color: green;">GeeksforGeeks</h1>
            <h2>HTML disabled Attribute</h2>
      
            <!--A disabled optgroup-->
            <select>
              <optgroup label="German Cars" disabled>
                <option value="mercedes">Mercedes</option>
                <option value="audi">Audi</option>
              </optgroup>
            </select>
        </body
    </html>    

    chevron_right

    
    

    Output:
    optgroup

    Supported Browsers: The browser supported by disabled attribute for <optgroup> element are listed below:

    • Apple Safari
    • Google Chrome 1.0
    • Firefox 1.0
    • Opera
    • Internet Explorer 8.0


My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.