What is Disabled Button in HTML?

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

What is Disabled Button in HTML?

A disabled button in HTML prevents the users from clicking the button. By default, disabled buttons are grey. HTML buttons can be disabled using the disabled boolean attribute. All HTML buttons are enabled by default unless specified.

button-disabled-1

Why Disabled Buttons are Needed?

Disabled button in HTML are needed in some scenarios when we want to prevent the users from clicking the button to prevent the action from being executed. Below are some scenarios when we may disable a button in HTML.

  • Disable a button when a form is submitted to prevent the users from clicking it again. For example, when the customer clicks login and waits for it to complete.
  • Disable a button until the user enters all the required details. For example, filling all the required details before registration.
  • Disable a button when a user is not authorized to click it. For example, disable the delete button for the users without admin access.

Syntax

The HTML syntax to disable a button is given below:

Alternatively, HTML buttons can be disabled/enabled with the JavaScript syntax below:

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Examples

Let's create a signup form that accepts name, email, and password. We should disable the signup button until the user enters all the details. We will disable and enable the button through HTML and JavaScript.

HTML

CSS

JavaScript

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Output

We disabled the button by default through the HTML attribute <button disabled>. We then controlled the enabling and disabling logic in JavaScript. Whenever the user types some values in the input field, it calls the validate() method that checks if all the values are entered. If yes, the button is enabled; else, disabled.

ARIA to the Rescue

ARIA, Accessible Rich Internet Applications is the set of attributes that we can add to the HTML element to make the web application accessible to users with disabilities who use assistive technologies such as screen readers.

When a button is disabled through the disabled attribute, the screen readers know that the buttons are disabled and communicate it to the user. But HTML buttons can also be disabled through javascript, and the screen readers don't know that the button is disabled. In such scenarios, we can add the aria-disabled="true" attribute to the button element to let the screen reader know that it is disabled.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Example

The button is disabled using JavaScript, and the attribute aria-disabled="true" is added to the button element to let the assistive technologies know that the button is disabled.

HTML

JavaScript

Difference Between Disabled and ARIA-disabled in HTML

DisabledARIA-disabled
Disables a button and prevents users from clicking itDoesn't disable a button. Just an attribute that tells the button is disabled. The button has to be disabled through JavaScript
Doesn't focus the button when the tab key is used to navigate through elementsButton is focussed when elements are navigated using the tab key

Supported Browsers

The disabled and aria-disabled attributes are supported by all major browsers such as Chrome, Internet Explorer, Edge, Firefox, Safari, Opera, etc.

Learn More

Please visit Scaler topic's HTML section to learn more about HTML

Conclusion

  • A disabled button in HTML prevents the users from clicking the button.
  • All HTML buttons are enabled by default unless specified.
  • HTML buttons can be disabled by adding the disabled attribute.
  • aria-disable="true" attribute is added to the button element to let the assistive technologies (Eg. screen readers) know it is disabled.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more