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.

Dominik Tran

Dominik Tran

Senior Full Stack Developer

22. July 2025

8 min

Advanced

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. 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.

Contents

What are custom HTML elements (Custom Elements)?

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.

The advantages of custom HTML elements for web development

Using custom elements brings plenty of advantages, above all in modular, scalable web development:

  • Reusability of components - once you create a custom HTML component, you can use it repeatedly across the whole site. That saves you time and minimises errors and site maintenance.
  • Better structure and legibility of HTML code - tags such as <product-card>, <login-form> or <custom-modal> speak for themselves. HTML becomes more semantic and easier to grasp for a new developer too.
  • Modularity and scaling - every component is independent. It has its own styles, logic and interface. That means simpler management on large projects.
  • Encapsulation thanks to the Shadow DOM - the Shadow DOM ensures CSS styles and JavaScript do not overlap with other parts of the page. A component keeps its isolation and stability, which markedly raises the frontend's reliability.
  • Compatibility across frameworks - Custom Elements are framework-agnostic. That means you can use them in vanilla JavaScript but in React, Vue or Angular too. They are fully supported by modern browsers.

Are you interested in a new design for your website?

Get in touch through our web form and we will be glad to take care of it.

Contact form

How to use Web Components in your own project (simply and comprehensibly)

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:

  1. Create the 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.

  1. Add a Shadow DOM (optional, but very useful)

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.

  1. Prepare an HTML template and styles

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.

  1. Register the new tag

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>.

Accessibility: think of users with disabilities

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:

  • Implement keydown events for the Enter and Space keys
  • Use role="button" (if you are not extending HTMLButtonElement)
  • Add aria-label or other ARIA attributes describing the function
  • Add tabindex="0" so that it is reachable by keyboard

SEO and custom HTML components: what to watch out for?

If 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.

  1. Search engines cannot see into the Shadow DOM

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.

  1. Keep HTML semantics

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.

  1. Show important content directly

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.

The future of custom HTML elements: where are Web Components heading?

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.

  • Greater adoption in large firms 

Giants such as Google, Microsoft and Salesforce actively use Web Components in their products.

  • The development of tools and libraries 

Frameworks such as Lit are arising that simplify writing custom elements without needing a lot of boilerplate code.

  • Greater support in the open-source community 

Ever more UI libraries are moving to an architecture based on Web Components, which simplifies sharing between various projects.

Possible improvements and wider adoption

  • A simpler developer experience 

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.

  • Better support for SSR and SEO 

Work is under way on better integration of Web Components into ecosystems where server-side rendering and indexing content matter.

A place in web standards

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.

Challenges, limits and performance: what to watch out for

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.

Compatibility with older browsers

  • Web Components are natively supported in most modern browsers (Chrome, Firefox, Safari, Edge), but older versions of Internet Explorer or older Android browsers may have problems.
  • If you need support for older devices, you will have to use a polyfill, which can affect performance and the bundle's size.

Problems with SEO and server-side rendering

  • Content inside the Shadow DOM is not directly visible to search engines, which can affect SEO.
  • The solution is server-side rendering (SSR) or at least a static fallback showing the basic content without JavaScript too.
  • If you are building a site that is to be well indexed (e.g. a blog or an e-shop), consider how you will render the components.

Performance demands

  • If you use too many complex custom elements with rich logic and animations, that can negatively affect a page's performance, above all on mobile devices.
  • Avoid nesting components pointlessly and use lazy loading where it makes sense.

Recommendations for effective use

  • Use semantic HTML where possible. For instance, instead of <custom-header> use <header> and merely put your component inside it.
  • Weigh the advantages and drawbacks, because for simple static blocks Web Components may not be needed. But if you are building a modular, reusable, dynamic system, they are a perfect solution.
  • Test in various browsers and track performance metrics, for instance through Lighthouse or Web Vitals.

Why you should start using custom HTML elements

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.

Recommended reading

The latest trends, proven practices and analyses from the digital world. Find out how to take your technology and marketing growth further.