HTML Concepts: Customized Built-In Elements
Published on March 25, 2023 (↻ July 2, 2023), filed under Development (RSS feed for all categories).
HTML allows to define custom elements, elements which enable authors to “build their own fully-featured DOM elements.”
One special type of custom element is the customized built-in element… a custom element built on an existing HTML element. This allows for reuse and extension of functionality already available.
The way customized built-in elements work is essentially this:
-
Pick an element to be built on and extended.
-
Define a class for it, similar to an autonomous custom element (or as MDN Web Docs shows).
-
Have that class extend the respective element (like
HTMLButtonElement
for abutton
element). -
For the
define
method, also specify anextends
option (likeextends: "button"
). -
To use the new customized built-in element, add an
is
attribute to the customized element in question, with the name of the customized element (like<button is="example-action">Action</button>
).
It’s useful to know that to ensure future-compatibility, this only works for elements defined in the HTML specification. That is, currently undefined elements but also deprecated elements cannot be extended like this, which includes legacy elements like isindex
, keygen
, or nextid
(sure, elements everyone has been waiting to customize!).
Yet in general, that’s it—though things become more interesting depending on the functionality to be added.
Customized built-in elements enjoy broad support, but are not currently supported by every browser. Follow the post thread on Mastodon for more details, or to share your information.
Have a look at other concepts—or review the summaries of the first eight concepts over at Frontend Dogma.
About Me
I’m Jens (long: Jens Oliver Meiert), and I’m a frontend engineering leader and tech author/publisher. I’ve worked as a technical lead for companies like Google and as an engineering manager for companies like Miro, I’m a contributor to several web standards, and I write and review books for O’Reilly and Frontend Dogma.
I love trying things, not only in web development (and engineering management), but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (Be critical, interpret charitably, and give feedback.)
Read More
Maybe of interest to you, too:
- Next: Highlights From “The Protestant Ethic and the Spirit of Capitalism” (Max Weber)
- Previous: Website Optimization Measures, Part XVIII
- More under Development
- More from 2023
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.
Get a good look at web development? Try WebGlossary.info—and The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.