SlideShare a Scribd company logo
Web Components
Who is this guy?
nikgraf
www.nikgraf.com
nik@blossom.io
Web Components
How to Use
<html>
<head>
<link rel="import" href="/path/calendar.html">
</head>
<body>
<custom-calendar></custom-calendar>
</body>
</html>
index.html
Web Components
Web Components
How to Use
<html>
<head>
<link rel="import" href="/path/to/map.html">
</head>
<body>
<open-street-map location-x=”13.252601623535156”
location-y=”52.45077881417044”
zoom=”5”>
</open-street-map>
</body>
</html>
index.html
Web Components
Web Components
Web Component
Web Components
Why?
Component
Component
Component
● Encapsulation
● Reusability
● Composability
Web Components
Easier and Faster Prototyping
<bootstrap-modal>
<h2>Welcome to Berlin</h2>
<open-street-map location-x=”13.252601623535156”
location-y=”52.45077881417044”
zoom=”5”>
</open-street-map>
</bootstrap-modal>
Web Components
Web Component
● HTML Templates inert chunks of clonable DOM
● Custom Elements create new HTML elements
● Shadow DOM encapsulation & boundaries inside of DOM
● HTML Imports import html documents
Web Components
Client Side Templating
<script id="clock-template" type="text/x-type-template">
<span class=”hour”></span>:
<span class=”minute”></span>
</script>
HTML
encourages run-time string parsing (.innerHTML)
user-supplied data → Cross-site scripting
Web Components
HTML Templates
<template id="clock-tmpl">
<span class=”hour”></span>:
<span class=”minute”></span>
</template>
<script>
var template = document.querySelector("#clock-tmpl");
// comment is a DocumentFragment
var comment = template.content.cloneNode(true);
</script>
Web Components
HTML
HTML Templates
Web Components
Working directly with the DOM
no runtime script parsing, smaller XSS attack vector
Hidden from document
cannot traverse into its DOM via JavaScript
Content gets parsed, not rendered
<script> tags aren’t executed, images aren't loaded,
media doesn't play, etc.
“
”
Shadow DOM
Web Components
Shadow DOM gives us markup encapsulation,
style boundaries, and exposes (to web
developers) the same mechanics browsers
vendors have been using to implement their
internal UI.
Eric Bidelman
Shadow DOM
Web Components
Let’s dig deeper
Web Components
Shadow DOM
<div id="clock"></div>
<script>
var host = document.querySelector('#clock');
// use webkitCreateShadowRoot for now
var shadowRoot = host.createShadowRoot();
shadowRoot.innerHTML = "<span>14</span>:
<span>30</span>";
</script>
Web Components
HTML
Shadow DOM
<h2>Black header</h2>
<script>
var host = document.createElement('div');
var shadowRoot = host.createShadowRoot();
var content = "<style>h2 {color: red}</style>";
content += "<h2>Red header</h2>";
shadowRoot.innerHTML = content;
document.body.appendChild(host);
</script>
Black header
Red header
Web Components
HTML
Shadow DOM
shadowRoot.resetStyleInheritance = false;
shadowRoot.applyAuthorStyles = false;
@host {
*:hover { color: red };
}
<span pseudo="x-hour"></span>
<my-clock id=”clock”></my-clock>
<style> #clock::x-hour { color: blue; } </style>
Web Components
HTML
Component CSS
clock.html Template
index.html
Custom Elements
var ClockPrototype = Object.create(HTMLElement.prototype);
ClockPrototype.createdCallback = function() {
this.impl.textContent = "14:20";
};
var Clock = document.register('custom-clock', {
prototype: ClockPrototype
});
var clock = new Clock();
// adds <custom-clock>14:20</custom-clock> to the DOM
document.body.appendChild(clock);
Web Components
tick_tock_clock.html
<link rel="import" href="clock.html">
<script>
var link = document.querySelector('link[rel=import]');
var content = link.import.querySelector('#clock');
</script>
HTML Imports
Web Components
<div id="clock">
<span class=”hour”>14</span>:
<span class=”minute”>30</span>
</div>
clock.html
index.html
Web Component
Web Components
<template id="clock-tmpl">
<span class=”hour”>14</span>:
<span class=”minute”>30</span>
</template>
<script>
var ClockProto = Object.create(HTMLElement.prototype);
ClockProto.createdCallback = function() {
var template = document.querySelector('#clock-tmpl');
var shadowRoot = this.createShadowRoot();
var clone = template.content.cloneNode(true);
shadowRoot.appendChild(clone);
};
document.register('my-clock', {prototype: ClockProto});
</script>
<link rel="import" href="clock.html">
<my-clock></my-clock>
clock.html
index.html
Use Web Components today
Web Components
Web Component (Polymer.js)
Web Components
<polymer-element name="my-clock">
<template>
<span class=”hour”>14</span>:
<span class=”minute”>30</span>
</template>
<script>Polymer('my-clock');</script>
</polymer-element>
<link rel="import" href="clock.html">
<my-clock></my-clock>
clock.html
index.html
Think Big
Web Components
<login-form></login-form>
Thanks for listening!
nikgraf
www.nikgraf.com
nik@blossom.io
Web Components
Further Reading
Web Components
Web Components
http://www.youtube.com/watch?v=fqULJBBEVQE
https://dvcs.w3.org/hg/webcomponents/raw-file/57f8cfc4a7dc/explainer/index.html
HTML Templates
http://www.html5rocks.com/en/tutorials/webcomponents/template/
https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html
HTML Imports
http://robdodson.me/blog/2013/08/20/exploring-html-imports/
https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/imports/index.html
Further Reading
Web Components
Shadow DOM
http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/
http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/
http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-301/
http://glazkov.com/2011/01/14/what-the-heck-is-shadow-dom/
https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html
Custom Elements
http://www.html5rocks.com/en/tutorials/webcomponents/customelements/
https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html
Resources
Web Components https://plus.google.com/103330502635338602217/posts
Lego Bricks http://commons.wikimedia.org/wiki/File:2_duplo_lego_bricks.jpg
Polymer Architecture http://www.polymer-project.org/
Icons http://pictos.cc/

More Related Content

PDF
Introduction to Web Components
PDF
Web components
PDF
Navigation and Link
PPTX
Tailwind CSS.11.pptx
PDF
Making DSpace XMLUI Your Own
PPTX
Dspace configuration on XMLUI DSpace
PDF
HTML Dasar : #8 Image
PDF
Lets make a better react form
Introduction to Web Components
Web components
Navigation and Link
Tailwind CSS.11.pptx
Making DSpace XMLUI Your Own
Dspace configuration on XMLUI DSpace
HTML Dasar : #8 Image
Lets make a better react form

What's hot (20)

PPTX
PDF
Tailwind CSS - KanpurJS
PPTX
What Is Virtual DOM In React JS.pptx
PDF
Angular - Chapter 3 - Components
PDF
Web Accessibility Evaluation with WAVE
PDF
CSS Layouting #4 : Float
PDF
CSS Dasar #9 : Inheritance
PPTX
Cascading style sheets (CSS)
PPT
Eye catching HTML BASICS tips: Learn easily
PPTX
Introduction to sass
PDF
Building an API with Django and Django REST Framework
PPTX
Chapter 18: Transitions, Transforms, and Animation
PDF
Web Components Everywhere
PPTX
jQuery Mobile
PDF
Tech talk on Tailwind CSS
PDF
Html frames
PDF
Simple React Todo List
PDF
Lab#9 graphic and color
PPTX
ASP.MVC Training
Tailwind CSS - KanpurJS
What Is Virtual DOM In React JS.pptx
Angular - Chapter 3 - Components
Web Accessibility Evaluation with WAVE
CSS Layouting #4 : Float
CSS Dasar #9 : Inheritance
Cascading style sheets (CSS)
Eye catching HTML BASICS tips: Learn easily
Introduction to sass
Building an API with Django and Django REST Framework
Chapter 18: Transitions, Transforms, and Animation
Web Components Everywhere
jQuery Mobile
Tech talk on Tailwind CSS
Html frames
Simple React Todo List
Lab#9 graphic and color
ASP.MVC Training
Ad

Similar to Web Components (20)

PDF
Web Components and Modular CSS
PDF
ENIB 2015-2016 - CAI Web - S01E01- Côté navigateur 3/3 - Web components avec ...
PDF
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
PPTX
Magic of web components
PPTX
An Introduction to Web Components
PDF
Web components are the future of the web - Take advantage of new web technolo...
PDF
Web Components: The future of Web Application Development
PPTX
Web Components Revolution
PPTX
Web Components: back to the future
PDF
BreizhBeans - Web components
PDF
Web components - a whirlwind tour
PDF
Web Components - The Future is Here
PPTX
Web components
PDF
Web components the future is here
PPTX
User-Customizable Web Components for Building One-Page Sites
PPTX
Liberarsi dai framework con i Web Component.pptx
PDF
Devoxx France - Web Components, Polymer et Material Design
PDF
Real World Web components
PPTX
Web Components
PPTX
Web components, so close!
Web Components and Modular CSS
ENIB 2015-2016 - CAI Web - S01E01- Côté navigateur 3/3 - Web components avec ...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
Magic of web components
An Introduction to Web Components
Web components are the future of the web - Take advantage of new web technolo...
Web Components: The future of Web Application Development
Web Components Revolution
Web Components: back to the future
BreizhBeans - Web components
Web components - a whirlwind tour
Web Components - The Future is Here
Web components
Web components the future is here
User-Customizable Web Components for Building One-Page Sites
Liberarsi dai framework con i Web Component.pptx
Devoxx France - Web Components, Polymer et Material Design
Real World Web components
Web Components
Web components, so close!
Ad

More from Nikolaus Graf (10)

PDF
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
PDF
Reason and GraphQL
PDF
Get started with Reason
PDF
Introduction to Serverless
PDF
Serverless Framework Intro
PDF
Rich text editing with Draft.js
PPTX
React + Redux Introduction
PDF
Redux Universal
PDF
React on es6+
PDF
AngularDart Introduction
Type Systems & Props Design - Exploring PropTypes, TypeScript, Flow & Reason
Reason and GraphQL
Get started with Reason
Introduction to Serverless
Serverless Framework Intro
Rich text editing with Draft.js
React + Redux Introduction
Redux Universal
React on es6+
AngularDart Introduction

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Electronic commerce courselecture one. Pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Review of recent advances in non-invasive hemoglobin estimation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Digital-Transformation-Roadmap-for-Companies.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Electronic commerce courselecture one. Pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Review of recent advances in non-invasive hemoglobin estimation
The AUB Centre for AI in Media Proposal.docx
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
NewMind AI Monthly Chronicles - July 2025
Spectral efficient network and resource selection model in 5G networks
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...

Web Components

  • 2. Who is this guy? nikgraf www.nikgraf.com nik@blossom.io Web Components
  • 3. How to Use <html> <head> <link rel="import" href="/path/calendar.html"> </head> <body> <custom-calendar></custom-calendar> </body> </html> index.html Web Components
  • 5. How to Use <html> <head> <link rel="import" href="/path/to/map.html"> </head> <body> <open-street-map location-x=”13.252601623535156” location-y=”52.45077881417044” zoom=”5”> </open-street-map> </body> </html> index.html Web Components
  • 9. Easier and Faster Prototyping <bootstrap-modal> <h2>Welcome to Berlin</h2> <open-street-map location-x=”13.252601623535156” location-y=”52.45077881417044” zoom=”5”> </open-street-map> </bootstrap-modal> Web Components
  • 10. Web Component ● HTML Templates inert chunks of clonable DOM ● Custom Elements create new HTML elements ● Shadow DOM encapsulation & boundaries inside of DOM ● HTML Imports import html documents Web Components
  • 11. Client Side Templating <script id="clock-template" type="text/x-type-template"> <span class=”hour”></span>: <span class=”minute”></span> </script> HTML encourages run-time string parsing (.innerHTML) user-supplied data → Cross-site scripting Web Components
  • 12. HTML Templates <template id="clock-tmpl"> <span class=”hour”></span>: <span class=”minute”></span> </template> <script> var template = document.querySelector("#clock-tmpl"); // comment is a DocumentFragment var comment = template.content.cloneNode(true); </script> Web Components HTML
  • 13. HTML Templates Web Components Working directly with the DOM no runtime script parsing, smaller XSS attack vector Hidden from document cannot traverse into its DOM via JavaScript Content gets parsed, not rendered <script> tags aren’t executed, images aren't loaded, media doesn't play, etc.
  • 14. “ ” Shadow DOM Web Components Shadow DOM gives us markup encapsulation, style boundaries, and exposes (to web developers) the same mechanics browsers vendors have been using to implement their internal UI. Eric Bidelman
  • 17. Shadow DOM <div id="clock"></div> <script> var host = document.querySelector('#clock'); // use webkitCreateShadowRoot for now var shadowRoot = host.createShadowRoot(); shadowRoot.innerHTML = "<span>14</span>: <span>30</span>"; </script> Web Components HTML
  • 18. Shadow DOM <h2>Black header</h2> <script> var host = document.createElement('div'); var shadowRoot = host.createShadowRoot(); var content = "<style>h2 {color: red}</style>"; content += "<h2>Red header</h2>"; shadowRoot.innerHTML = content; document.body.appendChild(host); </script> Black header Red header Web Components HTML
  • 19. Shadow DOM shadowRoot.resetStyleInheritance = false; shadowRoot.applyAuthorStyles = false; @host { *:hover { color: red }; } <span pseudo="x-hour"></span> <my-clock id=”clock”></my-clock> <style> #clock::x-hour { color: blue; } </style> Web Components HTML Component CSS clock.html Template index.html
  • 20. Custom Elements var ClockPrototype = Object.create(HTMLElement.prototype); ClockPrototype.createdCallback = function() { this.impl.textContent = "14:20"; }; var Clock = document.register('custom-clock', { prototype: ClockPrototype }); var clock = new Clock(); // adds <custom-clock>14:20</custom-clock> to the DOM document.body.appendChild(clock); Web Components tick_tock_clock.html
  • 21. <link rel="import" href="clock.html"> <script> var link = document.querySelector('link[rel=import]'); var content = link.import.querySelector('#clock'); </script> HTML Imports Web Components <div id="clock"> <span class=”hour”>14</span>: <span class=”minute”>30</span> </div> clock.html index.html
  • 22. Web Component Web Components <template id="clock-tmpl"> <span class=”hour”>14</span>: <span class=”minute”>30</span> </template> <script> var ClockProto = Object.create(HTMLElement.prototype); ClockProto.createdCallback = function() { var template = document.querySelector('#clock-tmpl'); var shadowRoot = this.createShadowRoot(); var clone = template.content.cloneNode(true); shadowRoot.appendChild(clone); }; document.register('my-clock', {prototype: ClockProto}); </script> <link rel="import" href="clock.html"> <my-clock></my-clock> clock.html index.html
  • 23. Use Web Components today Web Components
  • 24. Web Component (Polymer.js) Web Components <polymer-element name="my-clock"> <template> <span class=”hour”>14</span>: <span class=”minute”>30</span> </template> <script>Polymer('my-clock');</script> </polymer-element> <link rel="import" href="clock.html"> <my-clock></my-clock> clock.html index.html
  • 27. Further Reading Web Components Web Components http://www.youtube.com/watch?v=fqULJBBEVQE https://dvcs.w3.org/hg/webcomponents/raw-file/57f8cfc4a7dc/explainer/index.html HTML Templates http://www.html5rocks.com/en/tutorials/webcomponents/template/ https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html HTML Imports http://robdodson.me/blog/2013/08/20/exploring-html-imports/ https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/imports/index.html
  • 28. Further Reading Web Components Shadow DOM http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom/ http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/ http://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-301/ http://glazkov.com/2011/01/14/what-the-heck-is-shadow-dom/ https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/shadow/index.html Custom Elements http://www.html5rocks.com/en/tutorials/webcomponents/customelements/ https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html Resources Web Components https://plus.google.com/103330502635338602217/posts Lego Bricks http://commons.wikimedia.org/wiki/File:2_duplo_lego_bricks.jpg Polymer Architecture http://www.polymer-project.org/ Icons http://pictos.cc/