An attribute provides additional information to its element.
An attribute is written as name="value" inside the opening tag of an element.
Attribute names and enumerated attribute values are case-insensitive, but it is recommended to use lowercase.
Non-enumerated attribute values are case-sensitive.
An enumerated attribute accepts a predefined set of values.
<input type="text" />
<input type="password" />
<input type="email" />HTML data-* ⇄ JavaScript HTMLElement.dataset
<div data-weight="100">Box</div>const div = document.querySelector<HTMLDivElement>("div");
console.log(div?.dataset.weight); // "100"A boolean attribute is determined solely by its presence or absence. When the attribute is present, it is considered true; when it is absent, it is considered false. The actual value assigned does not matter.
<!--All checkboxes will be checked-->
<input type="checkbox" checked />
<input type="checkbox" checked="" />
<input type="checkbox" checked="true" />
<input type="checkbox" checked="false" />HTML Attributes are reflected in corresponding JavaScript properties.
Examples #
idElements cannot share the same
idvalue.classElements can share the same
classvalue and have multipleclassvalues.HTML <div class="common"></div> <div class="common another"></div>titleFor a mouse hovering tooltip.
rel