Introduction
Introduction
Introduction
Introduction
Contents
What are web components?
What are web components?
Web components are a set of web platform APIs that allow you to create new
Specifications
custom, reusable, encapsulated HTML tags to use in web pages and web apps.
Custom components and widgets build on the Web Component standards, will
Custom Elements
work across modern browsers, and can be used with any JavaScript library or
Shadow DOM framework that works with HTML.
Web components are based on existing web standards. Features to support web
ES Modules
components are currently being added to the HTML and DOM specs, letting web
HTML Template developers easily extend HTML with new elements with encapsulated styling and
custom behavior.
How do I use a web component?
Specifications
How do I define a new HTML element?
Web components are based on four main specifications:
Creating and using a shadow root
WEBCOMPONENTS.ORG Publish element
Custom Elements
Libraries for building web components
Shadow DOM
The shadow DOM specification defines how to use encapsulated style and
markup in web components.
ES Modules
HTML Template
The components on this site provide new HTML elements that you can use in your
web pages and web applications.
Using a custom element is as simple as importing it, and using the new tags in an
WEBCOMPONENTS.ORG HTML document. For example, to use the paper-button element: Publish element
There are a number of ways to install custom elements. When you find an
element you want to use, look at its README for the commands to install it. Most
elements today can be installed with NPM. NPM also handles installing the
components' dependencies. For more information on NPM, see npmjs.com.
For example, the paper-button overview describes the install process with npm:
This section describes the syntax for the cross-browser version of the Web
Components specification.
Use JavaScript to define a new HTML element and its tag with the
WEBCOMPONENTS.ORG customElements global. Call customElements.define() with the tag Publish
name youelement
want to create and a JavaScript class that extends the base HTMLElement.
<app-drawer></app-drawer>
<script>
// Create with javascript
var newDrawer = document.createElement('app-drawer');
// Add it to the page
document.body.appendChild(newDrawer);
// Attach event listeners
document.querySelector('app-drawer').addEventListener('open', function(
</script>
WEBCOMPONENTS.ORG Publish element
Many libraries already exist that make it easier to build web components. The
libraries section of the site has additional details but here are some you can try
out:
WEBCOMPONENTS.ORG Publish element
Hybrids is a UI library for creating Web Components with simple and
functional API.
Search custom elements LitElement uses lit-html to render
LAYOUTinto the element's
CALENDAR Shadow EMOJI
ROUTING DOM andTOOLBAR
adds
API to help manage element properties and attributes.
Polymer provides a set of features for creating custom elements.
Slim.js is an opensource lightweight web component library that provides
data-binding and extended capabilities for components, using es6 native
class inheritance.
Stencil is an opensource compiler that generates standards-compliant web
components.