Use the power of custom HTML elements
Today it is simply no longer enough to create static HTML pages alone. If we want to build sustainable, high-performing and well-organised applications, we need modern solutions.
22. July 2025
8 min
AdvancedToday it is simply no longer enough to create static HTML pages alone. If we want to build sustainable, high-performing and well-organised applications, we need modern solutions.
22. July 2025
8 min
AdvancedToday it is simply no longer enough to create static HTML pages alone. If we want to build sustainable, high-performing and well-organised applications, we need modern solutions. One of them is custom HTML elements, known as Custom Elements (the basic building block of Web Components). These HTML elements bring the option of creating reusable components that markedly simplify development and improve web applications' legibility and performance alike. In this article you will find out what custom HTML elements are, how they work, what advantages they have and how you can use them.
Custom HTML elements are special "hand-made" tags that behave like ordinary HTML elements (e.g. <button> or <input>). They help developers create their own parts of a website, such as buttons, banners or form elements. This is made possible by a technology called Web Components, which ensures such an element can easily be used several times.
Using custom elements brings plenty of advantages, above all in modular, scalable web development:
Get in touch through our web form and we will be glad to take care of it.
Think of a component as your own mini-block of a site. For instance a button, a product card or a contact form. You create it once and can then use it repeatedly anywhere on the page. That is exactly what Web Components are about (custom HTML tags with their own look and behaviour).
Here is a simple guide, step by step, on how to create such a component:
First, using JavaScript, you create a class (something like a set of instructions or a plan) that extends an ordinary HTML element. This step defines what your new component will do.
An example: you come up with your own button called <my-button>, which will have special behaviour when someone clicks it.
The Shadow DOM is something like a "protective bubble" you enclose your component in. Thanks to that its styles and scripts do not get out and at the same time no foreign styles can affect its look.
Think of it as your component's own little world. Clean, orderly and secure.
You need to teach the component how it should look and what it should contain. That can be done using the HTML <template> element or directly in JavaScript through so-called rendering.
You can, for instance, decide that your button is to be blue, have white text and show a message when clicked.
For the browser to know you have created a new tag, you have to tell it. Using the customElements.define command you connect the tag's name (e.g. <my-button>) with the class you created.
And that is that – from this moment you can use this tag anywhere in your HTML, just like <div>, <p> or <button>.
When creating custom HTML components, accessibility (a11y) is key. Ordinary HTML elements such as <button> ,<input> or <a> have built-in features for keyboards, screen readers and other assistive technologies. When you create your own elements, though, you have to add these features explicitly.
If you are creating a custom button (<my-button>), for instance, do not forget to:
keydown events for the Enter and Space keysrole="button" (if you are not extending HTMLButtonElement)aria-label or other ARIA attributes describing the functiontabindex="0" so that it is reachable by keyboardIf you want your website to be not only pretty and functional but well visible in search engines too, you should think about SEO optimisation when creating custom HTML components. Some technologies Web Components use can be a little more complicated for Google or other search engines to process. But do not despair — you only need to know a few principles and your website will be indexed properly.
When you use the Shadow DOM (which helps you isolate a component's styles and logic), bear in mind that search engines may not see the content inside it. That can be a problem if you show text, headings, products or other important content in components.
A tip: if possible, use server-side rendering (SSR) – that is, generate the component's content on the server so that search engines receive it as finished HTML code.
Alternatively you can use so-called fallback content – something like backup text that will be visible without JavaScript too.
Using semantic tags (e.g. <header>, <article>, <nav>, <footer>) helps search engines grasp your site's structure. If you create your own tags (e.g. <my-header>), take care not to destroy comprehensibility for robots.
The solution: instead of <custom-header>, which has no structure, use an ordinary <header> and "move" your functionality into it through a class or JavaScript. That way you gain all the component's advantages and at the same time keep legibility for search engines.
If something is to be indexed, you should generate it directly in the HTML, that is, without needing to wait for JavaScript. Many search engines do understand JS today, but the rule still applies: the simpler you make it for them, the better.
The solution: if you have a product card in <product-card>, for instance, make sure at least the basic information (name, price, description) is present in the resulting HTML. Either as a fallback or through SSR.
Custom HTML elements and Web Components generally appear ever more often in modern web applications. Although their arrival was slower, today they are firmly settling into practice. Above all thanks to their independence from frameworks, their reusability and how simply they integrate.
Giants such as Google, Microsoft and Salesforce actively use Web Components in their products.
Frameworks such as Lit are arising that simplify writing custom elements without needing a lot of boilerplate code.
Ever more UI libraries are moving to an architecture based on Web Components, which simplifies sharing between various projects.
Some parts of the specification are still fairly technical and complicated for beginners. There is room for improvement here. Above all in documentation and tooling.
Work is under way on better integration of Web Components into ecosystems where server-side rendering and indexing content matter.
Custom HTML elements are part of the official web standards (along with the Shadow DOM and HTML Templates), which means they are not tied to a particular library or framework. Their advantage is that they work the same in various environments, and it is exactly thanks to that that they can become the core of future design systems and web architectures.
Although custom HTML components are a very powerful tool, they are not without flaws. Here are a few things you should watch out for when using them.
Custom HTML elements are not new — the Custom Elements specification has existed since 2014 — but it is exactly their gradual refinement and stable support in browsers that today makes them a reliable part of an architecture. They offer modularity, legibility and real reusability where a project demands it.
Implementing them brings greater initial complexity and requires weighing questions such as accessibility, SEO or server-side rendering. Where you need to keep a consistent set of components, though, for instance in larger applications or design systems, investing in Web Components can quickly pay off in the form of cleaner code, simpler maintenance and a unified user interface.
Start first with a single component that eliminates repetition in your project. If deploying it brings a measurable improvement (faster development, fewer errors, better organisation), that is a signal that Web Components have their place in your project.
The latest trends, proven practices and analyses from the digital world. Find out how to take your technology and marketing growth further.
And don't forget to check out Invelity Extras – you'll find a marketing glossary, useful tools and plugins to make your work easier!
Invelity Extras