ArticleslgStudy

science

Web Components

Web Components is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Web Components rather than just read about it. In short: Web Components are a set of features that provide a standard component model for the web allowing for encapsulation and interoperability of individual HTML elements. Web Components are a popular approach when building microfrontends.

Key takeaways

  • Web Components belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Web Components to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Web Components from memory before moving on to harder problems.

Reference excerpt

Web Components are a set of features that provide a standard component model for the web allowing for encapsulation and interoperability of individual HTML elements. Web Components are a popular approach when building microfrontends. Primary technologies used to create Web Components include:

Custom elements APIs to define new HTML elements Shadow DOM encapsulated DOM and styling, with composition HTML templates HTML fragments that are not rendered, but stored until instantiated via JavaScript

Features

Custom elements There are two parts to Custom Elements: autonomous custom elements and customized built-in elements. Autonomous custom elements are HTML elements that are entirely separated from native HTML elements; they are essentially built from the bottom up using the Custom Elements API. Customized built-in elements are elements that are built upon native HTML elements to reuse their functionality.

Shadow DOM The Shadow DOM is a functionality that allows the web browser to render DOM elements without putting them into the main document DOM tree. This creates a barrier between what the developer and the browser can reach; the developer cannot access the Shadow DOM in the same way they would with nested elements, while the browser can render and modify that code the same way it would with nested elements. The impact of CSS scoped within the Shadow DOM of a particular element is that HTML elements can be encapsulated without the risk of CSS styles leaking and affecting elements that they were not supposed to affect. Although these elements are encapsulated with regard to HTML and CSS, they can still fire events that can be picked up by other elements in the document. The scoped subtree in an element is called a shadow tree. The element the shadow tree is attached to is called a shadow host. A Shadow DOM must always be connected to an existing element, either through attaching it as a literal element or through scripting. In JavaScript, Shadow DOMs are attached to an element using Element.attachShadow().

HTML template An HTML template defines a block of HTML content that is not rendered when the page loads, but can be instantiated during runtime. A template element is structured as follows:

Scripts within a template do not run, and resources are not fetched, until the content is cloned or added to the DOM.

Browser support Web Components are supported by current versions of all major browsers. Backward compatibility with older browsers is implemented using JavaScript-based polyfills.

Libraries There are many libraries that are built on Web Components with the aim of increasing the level of abstraction when creating custom elements. Some of these libraries are X-Tag, Slim.js, Polymer, Bosonic, Riot.js, Salesforce Lightning Web Components, DataFormsJS, Telepathy, and Wompo

Community There are numerous community efforts for the Web Components ecosystem. WebComponents.org provides an interface to search for any existing Web Components. Custom Elements Everywhere validates whether popular front-end frameworks are compatible and ready to use Web Components standard, with a set of pending bugs and available workarounds. Moreover, Vaadin Tutorials has a dedicated section that shows how those workarounds are used efficiently with example demo apps and similarly related topics.

History In 2011, Web Components were introduced for the first time by Alex Russell at Fronteers Conference. In 2013, Polymer, a library based on Web Components was released by Google. Polymer is canonical implementation of Material Design for web application user interfaces. In 2016, RequireJS was introduced as JavaScript library and AMD loader plugin for custom elements. In 2017, Ionic (mobile app framework) team built StencilJS, a JavaScript compiler that generates Web Components. In 2018, Angular 6 introduced Angular Elements that lets you package your Angular components as custom web elements, which are part of the web components set of web platform APIs. In 2018, Firefox 63 enabled Web Components support by default and updated the developer tools to support them. In 2018, LitElement was developed by the Google Chrome team as part of larger Polymer project. LitElement was designed to be a lightweight and easy-to-use framework for creating web components.

See also HTML Components Web framework Web resource

References

External links Official website

Worked examples

Example 1 — a first encounter with Web Components

Start with the simplest possible case. Write down what Web Components claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Web Components before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Web Components ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Web Components

In research
Web Components appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Web Components in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Web Components is common in secondary-school and first-year university syllabi. It links to neighbouring topics Web programming, Web standards, so understanding it makes those chapters shorter.
In everyday life
Look for Web Components outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Web Components” →

How to study Web Components in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Web Components means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Web Components out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Web Components in simple terms?

Web Components are a set of features that provide a standard component model for the web allowing for encapsulation and interoperability of individual HTML elements. Web Components are a popular approach when building microfrontends.

Why does Web Components matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Web Components?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Web Components.

Tags

  • Web programming
  • Web standards

Keep exploring