Boolean Attribute

Boolean attributes in HTML are attributes that, when present, are considered “true” and don’t require a value. They are commonly used for toggling certain behaviors or states, such as the `disabled` attribute for form elements.

Example:

HTML




<!DOCTYPE html>
<html lang="en">
 
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">
    <title>Boolean Attribute Example</title>
    <style>
        body {
            text-align: center;
        }
 
        h2 {
            color: green;
        }
 
        button {
            padding: 10px;
            font-size: 16px;
        }
    </style>
    <script>
        const toggleButton = () => {
            const buttonElement =
                  document.getElementById("myButton");
            buttonElement.disabled = !buttonElement.disabled;
        };
    </script>
</head>
 
<body>
    <h2>Welcome to Boolean Attribute Example</h2>
    <button id="myButton" onclick="toggleButton()">
          Click me (Toggle disabled attribute)
      </button>
</body>
 
</html>


Output:



What are HTML Attributes ?

HTML attributes are the entities that provide the extra information about the tags. Attributes are specified using name and value pair. Some HTML tags are used without attributes while for some tags it’s important to specify attributes along with them. In paired tags attributes are specified in the opening tag. The value of the attribute is specified between the quotes. They are used to add extra effects to the element.

Similar Reads

Syntax:

Content of the tag ...

Meta Tag Attributes

Meta tags provide important meta information about HTML documents. They are self-closing tags. Attributes of the meta tag are crucial for browser functionality, including search engine optimization, character set declaration, and viewport control....

Global Attributes in HTML

...

Event-handling Attributes

This type of attribute are applied on all types of HTML tags.Some of the commonly used global attributes are class ,id,style. “class” attribute is used to group elements and to style the grouped element and “id” attribute must be unique. It is used to apply functionality or styles to unique element....

Boolean Attribute

...