Open In App

How to specify that an input element should be disabled?

Last Updated : 19 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The disabled attribute for <input> element is used to specify that the input field is disabled. A disabled input is un-clickable and unusable. It is a boolean attribute. The disabled <input> elements are not submitted in the form.

Syntax:

<input disabled>

Example: In this example, to specify that an input element should be disabled in HTML, add the disabled attribute to the input tag. This attribute prevents users from interacting with the input field, visually indicating its disabled state. When the disabled attribute is present, it specifies that the input field is disabled. We can not write any content on the disabled input field.

HTML
<!DOCTYPE html>
<html>

<head>
    <title>
        How to specify that an input element
        should be disabled in HTML?
    </title>
    <style>
        label {
            display: block;
            padding: 10px;
        }
    </style>
</head>

<body style="text-align:center">

    <h2>
        Input element
        <br>should be disabled in HTML
    </h2>

    <label>Disabled Input Field:

        <!--A disabled input-->
        <input type="text" name="value" 
               value="This input field is disabled" 
               disabled>
    </label>

    <label>Input Field

        <!--A disabled input-->
        <input type="text" name="value" 
               value="Not disabled">
    </label>
</body>

</html>

Output:

disabledinput
Output

Supported Browsers

  • Apple Safari: 1.0
  • Google Chrome: 1.0
  • Firefox: 1.0
  • Opera: 1.0

Next Article

Similar Reads