# [Web Components][web-components-mdn] ## [Custom Elements][using-cusotom-elements-mdn] A set of JavaScript APIs that allow you to define custom elements and their behavior, which can then be used as desired in your user interface. ### Types of Custom Elements There are two types of custom element: - **Customized built-in elements** inherit from standard HTML elements such as `HTMLImageElement` or `HTMLParagraphElement`. Their implementation customizes the behavior of the standard element. - **Autonomous custom elements** inherit from the HTML element base class `HTMLElement`. Need to implement their behavior from scratch. A custom element is implemented as a class which extends `HTMLElement` (in the case of autonomous elements) or the interface to be customized customized (in the case of customized built-in elements). ```js class CustomParagraph extends HTMLParagraphElement { constructor() { // self is reference to this element self = super(); } } class CustomElement extends HTMLElement { constructor() { super(); } } ``` ### Registering & Using Custom Elements To make a custom element available in a page, call the `define()` method of `Window.customElements`. The `define()` method takes the following arguments: - `name`: The name of the element. This must start with a lowercase letter, contain a hyphen, and satisfy certain other rules listed in the specification's definition of a valid name. - `constructor`: The custom element's constructor function. - `options`: Only included for customized built-in elements, this is an object containing a single property extends, which is a string naming the built-in element to extend. ```js // register a customized element window.customElements.define("custom-paragraph", CustomParagraph, { extends: "p" }); // register a fully custom element window.customElements.define("custom-element", CustomElement); ``` ```html