They are a new HTML5 standard to build reusable components for the web. They can contain a set of custom elements, Javascript, and styles unique to a specific component.
What if browsers made it easier to build modular, more encapsulated code?
What if we could teach new elements to the browser?
...
...
...
...
Home
Profile
Messages
Custom Elements enable developers to create their own custom HTML/DOM elements. It enables easier component reuse.
var XFoo = document.registerElement('x-foo');
Now you can use <x-foo> wherever you want in the document.
By default, custom elements inherit from HTMLElement. The example above is equivalent to
var XFoo = document.registerElement('x-foo', {
prototype: Object.create(HTMLElement.prototype)
});
codepen.io/TimMansell/pen/ZYVmdX
var XJS = document.registerElement('x-js');
document.body.appendChild(new XJS());
or
document.registerElement('x-jsx');
document.body.appendChild(document.createElement('x-jsx'));
You need to have at least one '-' inside the name of your custom element.
Any tag names without '-' will result in an error.
x-component
x-web-component
xcomponent
x_component
You can create a custom element that extends a native HTML element's features.
var XFoo = document.registerElement('x-foo', {
extends: 'input',
prototype: Object.create(HTMLInputElement.prototype)
});
To use the element, use the original tag and specify the custom tag name using the "is" attribute.
The benefit of extending native elements is that even if JS is turned off or the browser doesn't support Custom Elements, the element will still show, but fallback to it’s base state.
.createdCallback() //Called after the element is created.
.attachedCallback() // Called when the element is attached to the document.
.detachedCallback() // Called when the element is detached from the document.
.attributeChangedCallback() // Called when one of attributes of the element is changed.
codepen.io/TimMansell/pen/ZYVmdX
Web Components
To load onto page.
codepen.io/TimMansell/pen/VYqVJR

With a Shadow DOM it is finally possible to write CSS rules that aren't global, enabling true modular development.
An element that has a shadow root associated with it is called a shadow host. The shadow root can be treated as an ordinary DOM element so you can append arbitrary nodes to it.
All markup and CSS are scoped to the host element.
CSS styles defined inside a Shadow Root won't affect its parent document and CSS styles defined outside the Shadow Root won't affect the main page.
var host = document.querySelector('button'),
root = host.createShadowRoot();
root.textContent = 'Hello, from the shadow world!';
codepen.io/TimMansell/pen/KwbbKm
See the Pen HTML Template and Shadow Dom by Tim Mansell (@TimMansell) on CodePen.
codepen.io/TimMansell/pen/embbYy
HTML Templates, Shadow DOM, and Custom Elements enable you to build components easier than before. But it's not efficient to load resources such as HTML, CSS, and JS separately.
HTML Imports allow you to load those resources as a single HTML file.
<head>
</head>
<body>
This is Custom Element
</body>

“Because Polymer makes use of polyfills, search engines should treat Polymer-based applications no differently than they do other javascript-based web apps. In fact, Google’s crawler understands JavaScript heavy applications.Going forward, it is a reasonable assumption that as use of native Shadow DOM increases, search engine providers will try to adapt to understand it, just as they have adapted to other new web technologies in the past.”Polymer Team
“Results from initial testing indicate that inclusion of ARIA roles, states and properties in content wholly inside the Shadow DOM works fine. The accessibility information is exposed correctly via the accessibility API. Screen readers can access content in the Shadow DOM without issue.“
Steve Faulkner
http://www.paciellogroup.com/blog/2012/07/notes-on-web-components-aria/
“Web Components, including Shadow DOM, are accessible because assistive technologies encounter pages as rendered, meaning the entire document is read as “one happy tree”.
Marcy Sutton
http://substantial.com/blog/2014/02/05/accessibility-and-the-shadow-dom/
But what about IE?
"a polyfill (or polyfiller) is downloadable code which provides facilities that are not built into a web browser. It implements technology that a developer expects the browser to provide natively, providing a more uniform API landscape."
Polymer is a library that uses the latest web technologies to let you create custom HTML elements.
<paper-toggle-button> Demo
<paper-tab> Demo
<paper-dialog> Demo
<core-toolbar> Demo
<core-collapse> Demo
<core-image> Demo
<core-ajax> Demo
<core-dropdown-menu> Demo
<core-icon> Demo
<core-media-query> Demo
<core-scaffold> Demo
I'm inside the element!
Import
<head>
</head>
Use
Toolbar
a web components gallery for modern web apps
What if the entire web platform was hosted on Github?
github.com/domenic/html-as-custom-elements