Let's talk about Web Components

Rate this content
Bookmark

Before the dawn of some of the most popular frameworks (read: React and Vue), there was Web components. Web Components take one of the best parts of these frameworks (reusable components) and combine it with the best parts of web development (native browser support and not needing to set up a build process). As if that's not enough, web components allow you use the same functions across any framework.

If at this point, you're wondering "If web components are so awesome, why haven't I heard about them before?", then you're in luck because that's exactly what this talk is about.

In this presentation, we'll take a look at what web components are, why web components are awesome, why web components can be a pain and how we can use web components both as a standalone tool and together with frameworks.

FAQ

Web components are a suite of technologies that allow you to create reusable HTML elements. They include features like custom elements, the shadow DOM, and HTML templates which enable developers to encapsulate functionality, style, and content separately from the main document.

Custom elements are part of the web components suite that allows developers to define new HTML tags with custom behavior. You can create your own HTML tags using the custom elements API, enabling more modular and reusable code.

The shadow DOM is a technology within web components that allows you to encapsulate elements, functionality, and styles, keeping them separate from the rest of the document. This means changes in the shadow DOM do not affect the main document and vice versa.

HTML templates in web components are used to declare fragments of HTML that can be cloned and inserted in the web document multiple times. The content inside a template tag is not rendered until it is activated via JavaScript, allowing for efficient DOM manipulation.

Yes, web components are designed to be cross-framework compatible, meaning they can be used with various frameworks like React, Angular, and Vue. This interoperability allows for the reuse of web components across different projects and frameworks.

Web components offer several benefits including reusability of code, encapsulation of functionality and style, and compatibility across different browsers and frameworks without the need for additional libraries or tools. They simplify the development process and enhance maintainability.

No, web components do not require any installation. They are supported natively in most modern browsers, enabling developers to use them directly without additional setups or tools.

Jemima Abu
Jemima Abu
32 min
22 Oct, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Web Components are a suite of technologies that allow you to create reusable HTML elements, combining the fun of React with regular HTML. Custom elements and the shadow DOM are key features of Web Components, allowing you to define new elements, encapsulate functionality and styles, and interact with a separate DOM. HTML templates serve as placeholders for content to be rendered later in custom components. Custom elements and HTML templates are cross-framework compatible and can be used in React, Angular, Vue, or any other framework.

Available in Español: Hablemos de los Componentes Web

1. Introduction to Web Components

Short description:

Let's talk about web components. I'm a self-taught frontend developer and a school taught systems engineer from Lagos, Nigeria. I like to build things with HTML and CSS. When I was first learning React, I didn't understand why things were the way they were. I prefer using HTML. Web Components are a suite of technologies that allow you to create reusable HTML elements. It's like using regular HTML, but with all the fun of React. Custom elements are an API that allow you to define new elements and their behavior. The shadow DOM allows you to encapsulate elements, functionality, and styles.

Let's talk about web components. So I should probably introduce myself first. I'm a self-taught frontend developer and a school taught systems engineer from Lagos, Nigeria. So I'm a long way from home, but I live in London now, so not that long. And you can find me online anywhere at JemimaAbu. So that's LinkedIn, Twitter, Medium. I make my username easy, so you guys don't have to go to stress to stalk me. It's all there.

All right. So let's get into it. Web components, what are they? So I'd like to preface by saying why I wanted to give this talk. I like to build things with HTML and CSS. I'm not a huge fan of JavaScript. When I was first learning React, I didn't understand why things were the way they were. I didn't understand why I had to use set states to change a state property, but then you couldn't just change it as a variable. It didn't make sense to me. So personally I prefer using HTML.

What I don't like about HTML is if I want to create six blocks of the same thing, I have to copy and paste the same thing many times over. And that's what I do like about React. And I was like, is there a way to have the simplicity of HTML with the reusability of React? And the answer was Web Components. So basically Web Components are a suite of technologies that allow you to create reusable HTML elements. So right off the bat, they're already there in your browser. You don't need to do any installation. It's like using vanilla HTML. Is that what it's called? It's like using regular HTML, but with all the fun of React.

And how does it work? So first of all, we have our custom elements. Custom elements are an API that allow you to define new elements and their behavior. So you can create your own HTML tags to use. And then we have the shadow DOM, which sounds very cool and I like it. Which allows you to encapsulate elements, functionality, and styles.

2. HTML Templates and Repeating Elements

Short description:

So this is what allows you to remove your custom elements from the regular flow of the page and just have it in a different DOM. And then finally we have HTML templates. So I was going to go through a little bit of code to show what I'm talking about. This is a simple blog template that we create in regular HTML. So if you're using regular HTML for this, it's just a lot of copying and pasting and changing the content. So first we're gonna look at what it looks like in regular HTML. The regular HTML is just a lot of pasting of the div with the same content everywhere. And then we have the method I usually use when I'm trying to repeat things. So on my portfolio page, if I was trying to repeat the websites I've built, I usually just create an array with all the content I need and then I render that on the page using vanilla JavaScript.

So this is what allows you to remove your custom elements from the regular flow of the page and just have it in a different DOM. Which is fun. And then finally we have HTML templates. So these are the custom tags that you're actually rendering on the pages. Yeah.

So I was going to go through a little bit of code to show what I'm talking about. So this is a simple blog template that we create in regular HTML. So if you're using regular HTML for this, it's just a lot of copying and pasting and changing the content. So let's see some code. Which is the part I'm good at. All right.

So first we're gonna look at what it looks like in regular HTML. Click. So we have this... We have our code up here. And the regular HTML is just a lot of pasting of the div with the same content everywhere. So I'm gonna zoom in. There we go. So you can see you just have the post div and it's just repeated multiple times throughout the page. Because that is what HTML does. It does not give you variety in how you decide to code. And then we have the method I usually use when I'm trying to repeat things. So on my portfolio page, if I was trying to repeat the websites I've built, because I use basic HTML to build my portfolio page, instead of having to write them all at the same time and then just changing the content, I usually just create an array with all the content I need and then I render that on the page using vanilla JavaScript. So if we're going to do that for this... It's a hard scroll bar. If we're going to do that for this thingy, it would look something like this. So I was meant to be live coding, but then I realized that that's just... I am not brave enough to write code live. Sometimes things go wrong and I break down, and I'm not doing that. So if you were doing this with vanilla JavaScript, it would be something like...

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

The Good, The Bad, and The Web Components
JSNation 2023JSNation 2023
29 min
The Good, The Bad, and The Web Components
Top Content
There has been no shortage of both fair and unfair criticism toward Web Components from a wide range of folks that build for the web, including but not limited to JavaScript Framework authors in supposed competition with the platform. In this talk I'll show you how to navigate and simplify the multifaceted landscape of web components, satisfying common criticisms and showing how you can Use the Platform most effectively today.
It's Time to De-Fragment the Web
React Day Berlin 2022React Day Berlin 2022
34 min
It's Time to De-Fragment the Web
Top Content
Over the past few years, the number of web frameworks available to us has exploded. In some ways, the breadth of choice is a clear win for our ecosystem. However, for many of us, it also comes with harsh drawbacks: - Have you ever used a popular open-sourced component built for framework A, and wished it existed in framework B? What about a design system library? - Does your company have frontends built in different frameworks, and your web teams are frustrated about the wasted hours needed to achieve a consistent design system? - Does your team build SDKs for web frameworks, and must manually re-write them for each framework? The solution to all 3 of these problems exists today. To fully understand it, we must first examine today’s web frameworks, re-think what a component should look like, and introduce a new Intermediate Representation of our components. This is what we have done at Builder.io when we created Mitosis, and we’re excited to share it with everyone.
Web Components, Lit and Santa 🎅
JSNation Live 2021JSNation Live 2021
28 min
Web Components, Lit and Santa 🎅
Get started with Web Components – enabling you to define new HTML elements that work everywhere regular HTML does. This talk will focus on Lit, a suite from Google that helps you create WCs with features you'd expect like data-binding and declarative definitions. It'll also cover how we've used them to build one of the web's jolliest sites, Google's Santa Tracker 🎅
Authoring HTML in a JavaScript World
React Summit US 2023React Summit US 2023
21 min
Authoring HTML in a JavaScript World
 In this talk, Tony shows how an authoring and semantic HTML-first approach to JSX template work leads to more readable, maintainable, and accessible UI components. He demonstrates how to think through implementing a UI prototype in a semantic way, authoring HTML before visuals. He shows how accessible markup improves performance, reduces DOM size, minimizes time spent on CSS, and reduces cognitive load not only for developers, but also for all our users, no matter how they consume our sites and applications.
Immutable Web Apps
JSNation 2022JSNation 2022
20 min
Immutable Web Apps
Resolving dependencies when they are all bundled together is easy. Resolving dependencies when they are in being loaded via script tags is much more challenging. The goal of this talk is to explain how Meltwater handles dependency resolution when building native Web Component based applications that rely on packages published by many different teams.
Web Components are awesome!
JSNation 2022JSNation 2022
10 min
Web Components are awesome!
Ever wondered how by placing "video" or "audio" into your HTML, you get a media player with controls included? Or how, depending on the type attribute, "input" can be a button, a place to enter text, select a date or file, color picker and more? What if you could create your own element? The answer: Web Components! 🤯 In this talk, we’ll take a look at what Web Components are, how to make one and include it into an application.

Workshops on related topic

Web Components in Action
JSNation Live 2021JSNation Live 2021
184 min
Web Components in Action
Workshop
Joren Broekema
Alex Korzhikov
2 authors
The workshop extends JavaScript programming language knowledge, overviews general software design patterns. It is focused on Web Components standards and technologies built on top of them, like Lit-HTML and Lit-Element. We also practice writing Web Components both with native JavaScript and using Lit-Element. In the end we overview key tooling to develop an application - open-wc.