Web Components. What are they? Pros, Cons and more.

Reusing code is a smart thing to do when developing, is more than a good practice, it should be done as much as possible to keep the code clean and make it scalable. Web components are a pretty interesting approach for reusing code which traditionally has not been so easy for custom markup structures.
On this article we will enter into the web components world, explain what is it, the technologies it uses, how can we implement it and it’s pros and cons. So at the end we should have a better understanding of the concept and a base knowledge to be able to make a informed decision when deciding to use it in our projects.
What are Web Components?
When we talk about Web Components we are basically talking about our own HTML tags which are defined in JavaScript code, are reusable, their functionality is encapsulated and can be used in any web project.
A web component will look like this:<my-web-component>, and will have its unique styling and functionality. An advantage of web components is that can be used with any JavaScript framework or library and it works across most modern browsers.
Web Components Technology
Web components are not a technology by itself, instead web components are based on the combination of three technologies that can be used together to create a versatile custom HTML tag.
- Custom Elements: This is the base of the web components, is an specification that allows developers to create new HTML tags and to define their behavior and style using nothing more than JavaScript, HTML and CSS, which can then be used as desired in the user interface. The result is less and modular code that can be reused.
To create a Custom Element we need to declare a class extending HTMLElement and then register it by using the customElements.define() method.









