CKTIS / HTML
is — extending a built-in HTML element
The is attribute identifies a custom element definition that extends a built-in HTML element. The element retains its native semantics and behavior while gaining author-defined functionality.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<button is="demo-button" type="button">Demo</button>The is attribute creates a customized built-in element. Its value must be a valid custom element name containing a hyphen, such as demo-button. It is not a boolean attribute.
The class extends the appropriate interface, such as HTMLButtonElement, and registration through customElements.define() supplies { extends: "button" }. The base tag name must match extends. The element retains button as its localName, native button semantics, and support for disabled.
An autonomous element uses its own tag name; is must not be specified on it and will not apply an extension there. Changing or adding is through setAttribute() after creation does not change an element's type. For programmatic creation, use document.createElement("button", { is: "demo-button" }).
The example registers the definition after the button has been parsed, causing the button to be upgraded. However, customized built-in elements are not supported universally across browsers; check your target environments.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>is example</title>
<button is="demo-button" type="button" id="demo">Demo</button>
<script>
class DemoButton extends HTMLButtonElement {
message() {
return "custom behavior";
}
}
customElements.define("demo-button", DemoButton, { extends: "button" });
const button = document.getElementById("demo");
console.log(button.localName);
console.log(button instanceof DemoButton);
console.log(button.message());
</script>
</html>Result
button true custom behavior
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.