×

HTML Button Disabled

The HTML <button> element has many attributes, one of them is the disabled attribute. The button on which you apply the disabled attribute will not work, or we can say that button becomes an unclickable button.

The disabled attribute is either true or false, which means it is a Boolean attribute. You cannot provide any value to the disabled attribute. You can add the disabled attribute inside the button element without assigning any value to it.

The button element will become a non-clickable or unusable element.

Syntax:

<button type="button" disabled> Click here </button>

Examples of HTML Button Disabled

Example 1:

This example shows the use of the disabled attribute. We will apply the disabled attribute to the login button element to make it unusable.

<!DOCTYPE html>   
<html>   
<head>  
<meta name="viewport" content="width=device-width, initial-scale=1">  
    <title>
        Example 1 of HTML Font Size
    </title>
    <style>
        .container{
            width: 250px;
            height: 160px;
            border: 2px solid brown;
            padding: 20px;
            background-color: rgb(138, 81, 81);
            color: white;
            text-align: center;
        }
    </style>   
</head>    
<body bgcolor="BurlyWood">    
 <h1> Login Form </h1>
    <form>  
        <div class="container">   
            <label> Username : </label>   
            <input type="text" placeholder="Enter Username" name="Username" required> <br> <br>  
            <label> Password : </label>   
            <input type="Password" placeholder="Enter Password" name="Password" required> <br> <br> 
            <input type="checkbox" checked> Remember me
            <button type="Submit" disabled> Login </button>    
            <button type="Button" class="cancelbutton"> Cancel </button> <br> <br>
            Forgot <a href="#"> Password? </a>   
        </div>   
    </form>     
</body>     
</html>

Output:

The output shows a login form with a disabled login button. As you can see, the disabled login button color becomes grey after adding the disabled attribute inside the button element. When you click the login button, it will not work.

HTML Button Disabled

Example 2:

We are creating a responsive registration form using HTML and JavaScript in this example. A form consists of input fields: first name, middle name, last name, email, a radio button to specify the gender, and a submit button. We will use the disabled attribute inside the submit button to disable the button element.

<!DOCTYPE html>  
<html>  
<head>  
<meta name="viewport" content="width=device-width, initial-scale=1">  
<title>  
Example 2 of HTML Button Disabled  
</title>  
<style>  


body {  
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif, Helvetica;  
background-color: rgb(129, 58, 70);  
}    
.container {  
padding: 40px;  
background-color: rgb(67, 188, 228);  
}  
  
input[type=text] {  
  width: 100%;  
  margin: 6px 0 20px 0; 
  padding: 16px;  
  border: none; 
  background: #fff3f3;  
  display: inline-block;  
} 


input[type=text]:focus {  
background-color: rgb(227, 250, 216);  
outline: none;  
}  
 div {  
            padding: 10px 0;  
        }   
  
button {  
  color: red;  
  padding: 16px 20px;    
  margin: 8px 0;  
  border: none;  
  cursor: pointer;  
  width: 100%;  
  
  opacity: 0.9;  
}  
</style>  
</head>  
<body>  
<form>  
<div class="container">  
<center>    
<h1> Registration Form </h1>   
</center>  
<label> Firstname: </label>   
<input type="text" name="first name" placeholder= "Enter your Firstname" size="15" required />   
<label> Middlename: </label>   
<input type="text" name="middle name" placeholder="Enter your Middlename" size="15" />   
<label> Lastname: </label>    
<input type="text" name="last name" placeholder="Enter your Lastname" size="16"required />   
<div>  
<label>   
Gender :  
</label><br>  
<input type="radio" value="Male" name="gender" checked > Male   
<input type="radio" value="Female" name="gender"> Female   
<input type="radio" value="Other" name="gender"> Other  
</div>  
<label for="email"> Email: <label>  
<input type="text" placeholder="Enter Email ID" name="email-id" required>  
In this example, we will use the disabled attribute inside the submit button and disable the submit button. When you click on submit button after filling out the form, the form will not submit.
<button type="submit form" value="submit form" disabled> Submit Form </button>  
</form>  
</body>  
</html>

Output:

The output shows a registration form containing various input fields and types of buttons. The submit button is shown as disabled in the below result. The color of the button fades automatically when the disabled attribute is applied. We cannot submit the form after filling the details.

HTML Button Disabled

Browser Support:

It supports the following browsers:

  • Microsoft Edge
  • Mozilla Firefox
  • Google Chrome
  • Internet Explorer
  • Safari
  • Opera

Related Topics

HTML <summary> tag

When we simply want to show the primary heading or topic name of hidden detailed material to users, then we can achieved this by using the summary tag. This makes it...

2 minutes read.

HTML Code Tag

The code tag in HTML is a phrase tag used to insert a piece of computer programming code. In HTML there is a separate tag named as <code> tag. Sometimes,...

3 minutes read.

HTML5 Tags

HTML5 Tags A list of newly included tags is provided in HTML5. These HTML 5 tags (elements) provide a better structure for the document. This list shows description of all HTML...

3 minutes read.

HTML Search Box

The HTML search box is also known as the search bar. It is an input text field that is used to search the content. If the users want to explore...

7 minutes read.

HTML 5 Tutorial

What is HTML5? HTML5 is a programming language which stands for the acronym Hyper Text Markup Language 5. It is program that enables the appearance of web pages to be changed, as well as changes...

5 minutes read.

HTML Anchor

HTML Anchor The HTML anchor tags define a hyperlink that links to other pages on one page. It can create hyperlinks to any web page and files, locations or any other...

3 minutes read.

HTML <style> tag

The section of information that we want to style is contained in html style tag. It includes CSS, which is used to design the text and images in the web page. Syntax: <head> <title>…………....

3 minutes read.

HTML Event Attributes

HTML Event Attributes If a browser responds to the user behavior, an event is called. For example, if we click on the submit button, a box of details will appear on...

4 minutes read.

Html <colgroup> Tag

A HTML table's column group is specified by the "colgroup" tag. If you want to apply various properties to one or more <col> elements in an HTML table, then you...

4 minutes read.

Html &lt;Col> Tag

You can write the col tag inside the table tag after the thead, tbody, foot, and tr tags. You can also apply it after the caption tag (in which the...

4 minutes read.

Html Wbr Tag

The Line Break Opportunity element A word break opportunity is a place in text from where the browser breaks a line. This opportunity is represented by the element wbr in the...

2 minutes read.

Html &lt;datalist >Tag

The autocomplete feature in HTML files is provided by the <datalist> tag. It can be used in conjunction with an input tag to enable users to quickly fill out form...

4 minutes read.

HTML <br> tag

HTML is referred to as Hyper Text Markup Language, which is the most popular language for creating Web pages. HTML explains the construction of a Web page. It contains a...

4 minutes read.

HTML Date

The input element in HTML has several attributes. One of its attributes is the type attribute which creates a calendar in an order that a user can select a date...

5 minutes read.

HTML Basic Tags

Heading Tags: This tag represents the document header. It is said to be a good practice if every document starts with Heading. Heading tags ranges from H1 to H6 i.e....

3 minutes read.

How to add JavaScript to HTML

JavaScript is one of the most important languages today. It is a high-level, interpreted, lightweight programming language that makes web pages more interactive. It is a language of the web....

5 minutes read.

HTML Layouts

HTML Layouts HTML templates provide a way for well-managed, well-structured responsive web pages to be organized. We could say that the HTML layout specifies how web pages can be set up....

4 minutes read.

HTML <script> Tag

For embedding a client -side script, we use script tag in html tag. This <script> tag can be used for containing scripting statements. It can also point another external script file...

2 minutes read.

Html &lt;center> Tag

The term HTML refers to Hyper Text Markup Language. The most widely used markup language for making web pages is HTML. A structure of web page is described in HTML....

3 minutes read.

HTML Images

HTML has <img> tag to display image on the web pages or web application. This tag is an empty tag i.e. we don't have to close this tag while using. SYNTAX: <img src="source address" attributes="alt, height, width"> Example: <html>   <body>   <center>Image tag Example</center>   <img src="https://www.tutorialandexample.com/resources/images/favicon.png"    alt="tutorialandexample"/>   </body>   </html> Output: Image...

1 minute read.