-
Notifications
You must be signed in to change notification settings - Fork 23.1k
Expand file tree
/
Copy pathindex.md
More file actions
38 lines (29 loc) · 1.78 KB
/
index.md
File metadata and controls
38 lines (29 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
---
title: Boolean attribute (HTML)
slug: Glossary/Boolean/HTML
page-type: glossary-definition
sidebar: glossarysidebar
---
A **boolean attribute** in {{Glossary("HTML")}} is an {{glossary("attribute")}} that represents `true` or `false` values. If an HTML tag contains a boolean attribute — no matter the value of that attribute — the attribute is set to `true` on that element. If an HTML tag does not contain the attribute, the attribute is set to `false`.
If the attribute is present, it can have one of the following forms:
- the attribute name alone; e.g., `attribute`, meaning its implicit value is the empty string
- the attribute with a value of the empty string; e.g., `attribute=""`
- the attribute with a value of the attribute's name itself, with no leading or trailing whitespace and case ignored; e.g., `attribute="attribute"`, `attribute="ATTRIBUTE"`
> [!NOTE]
> The strings "true" and "false" are invalid values. To set the attribute to `false`, the attribute should be omitted altogether. Though modern browsers treat _any_ string value as `true`, you should not rely on that behavior.
Here's an example of a HTML boolean attribute `checked`:
```html
<!-- The following checkboxes will be checked on initial rendering -->
<input type="checkbox" checked />
<input type="checkbox" checked="" />
<input type="checkbox" checked="checked" />
<input type="checkbox" checked="Checked" />
<!-- The following checkbox will not be checked on initial rendering -->
<input type="checkbox" />
```
## See also
- [Boolean attributes](/en-US/docs/Web/HTML/Reference/Attributes#boolean_attributes)
- [Boolean attributes](https://html.spec.whatwg.org/#boolean-attributes) in HTML specification
- Related glossary terms:
- {{Glossary("Attribute")}}
- {{Glossary("Enumerated", "Enumerated attribute")}}