SlideShare a Scribd company logo
1 of 68
Download to read offline
BEM METHODOLOGY 
Vittorio Zaccaria 
September 17th, 2014
ME 
Enthusiast about Javascript, CSS and Web 
technologies 
Looking forward to invest into promising 
swiss startups 
www.vittoriozaccaria.net 
vittorio.zaccaria@gmail.com
WHAT YOU WILL GET FROM THIS SEMINAR
understand how to deal with the 
complexity of your CSS (BEM)
know which tools can 
help you manage your CSS projects
a look at the future of front-end design 
technologies (web components)
GOING CRAZY WITH CSS
which selectors match a given element?
.label 
.label.left 
.left 
.label.left 
CSS
yup, it can become overwhelming
.label 
.label.left.small 
.left 
.small 
.label.left 
.label.small 
.left.small 
.label.left.small 
CSS
specificity
#a 
{ 
background-color : blue; 
} 
.big.container > .b.c 
{ 
background-color : red; 
} 
.big.container 
#a.b.c 
CSS
#a 
{ 
background-color : blue; 
} 
#a.b.c 
.big.container > .b.c 
{ 
background-color : red; 
} 
.big.container 
CSS
adjustment rules
.header 
.header 
.logo 
.logo 
.header .logo
cognitive load might mean 
waste of time and money in your team
A MORE STRUCTURED APPROACH
CSS Design CSS Engineering (Scientific Principles)
Code independence, predictability 
HTML
HTML 
Project 2 
Project 1 
Code reuse 
HTML
BLOCK ELEMENT MODIFIER
it’s a set of formalized guidelines developed by 
Yandex, RU in the past few years 
it is mainly a naming and structuring 
methodology for CSS/HTML
How to define and 
structure modules for 
CSS, enabling separation 
How to of concerns and reuse 
organize files 
Tools for manipulating 
BEM compliant specs 
although it has more…
BEM defines the concept of “block” for CSS 
we will call it also “component” or “module”
block 
• html + style rules 
• independent w.r.t. other blocks 
• can be used in different parts/projects
how BEM would define this block 
1. use only one class - they flatten specificity 
2. no positioning information in it 
3. dont introduce relative adjustment
.art-preview { 
width: 30%; 
... 
} 
.art-preview 
CSS 
no parent blocks here, or 
we’d compromise reuse and mobility
modifier 
changes a small amount of properties of a block 
it is another class to be added to the block itself
.art-preview { 
width: 30%; 
} 
! 
.art-preview__size_small { 
width: 15%; 
... 
} 
! 
.art-preview 
CSS 
.art-preview.art-preview__size_small
name spacing for modifiers 
.art-preview__size_small 
Separator 
type of modification 
value of modification 
CSS
modifiable through JS 
block(‘art-preview’).toggle(‘size_small’) 
adds/removes class 
JS
element 
styles only a piece of a block 
this piece can’t live outside the block
.art-preview 
element of .art-preview
name spacing for elements 
.art-preview--title 
Separator 
name of the element 
CSS
.art-preview { 
... 
} 
! 
.art-preview--title { 
font-size: 1.5rem; 
... 
} 
.art-preview 
CSS 
.art-preview--title
.art-preview--title { 
font-size: 1.5rem; 
... 
} 
! 
.art-preview__size_small .art-preview—title 
{ 
font-size: 1.2rem; 
... 
} 
.art-preview--title 
.art-preview__size_small .art-preview--title 
CSS
.art-preview--title { 
font-size: 1.5rem; 
... 
} 
! 
.art-preview__size_small .art-preview—title 
{ 
font-size: 1.2rem; 
... 
} 
.art-preview--title 
.art-preview__size_small .art-preview--title 
CSS
NESTING
tab block 
.tab { 
... 
} 
CSS
tab block 
.tab { 
... 
} 
! 
.card { 
... 
} 
CSS 
card block
NON BEM
tab block 
.tab { 
... 
} 
! 
.card { 
... 
} 
! 
.tab .card { 
// set margins 
} 
CSS 
card block
BEM
tab block 
.tab { 
... 
} 
! 
.card { 
... 
} 
! 
.card.tab——card { 
// set margins 
} 
CSS 
card block 
not using generations to express nesting 
.card.tab--card
child changes parent 
.form.form——has—modal 
.modal 
.form { 
... 
} 
! 
.modal { 
... 
} 
! 
.form.form——has—modal { 
// disable input 
} 
CSS
DRAWBACKS
long names 
.article-preview——title.article-preview—— 
title__highlighted 
CSS
abbreviate 
.artp——title.artp——title__hl 
CSS
use css preprocessors 
LESS 
.header { 
background: white; 
&——title { 
font: bold 24px/1 sans-serif; 
&__featured { 
font-size: 30px; 
} 
} 
} 
CSS 
.header { 
background: white; 
} 
.header——title { 
font: bold 24px/1 sans-serif; 
} 
.header——title__featured { 
font-size: 30px; 
} 
src: http://frontendbabel.info/articles/bem-with-css-preprocessors/
BEMTO 
HTML 
src: https://github.com/kizu/bemto 
JADE 
+b.block1 
+e.element1 Foo 
+b.block2 
+e('a')(href="#bar").element Bar 
+e.element2 Baz 
<div class="block1"> 
<div class="block1__element1"> 
Foo 
</div> 
<div class="block2"> 
<a class="block2__element" 
href="#bar">Bar</a> 
</div> 
<div class="block1__element2"> 
Baz 
</div> 
</div>
seriously, try jade, even without BEM 
http://jade-lang.com/
WHAT ABOUT SMACSS - MVCSS?
MVCSS BEM SMACSS 
block 
element 
modifier 
Scalable and modular CSS 
https://smacss.com/ 
base 
applies to tags and ids 
layout Nesting similar to 
grids and stuff 
modules 
subclassing 
states 
Modular View CSS 
http://mvcss.github.io/ 
foundation reset 
structures 
not reusable patterns 
components reusable patterns
THE FUTURE
Polymer 
http://www.polymer-project.org/
create your own tags! 
HTML 
<!-- Polyfill Web Components support for older browsers --> 
<script src="components/platform/platform.js"></script> 
! 
<!-- Import element --> 
<link rel="import" href="counter.html"> 
! 
<!-- Use element --> 
<my-counter counter="10">Points</my-counter>
HTML 
<!-- Define element --> 
<polymer-element name="my-counter" attributes="counter"> 
<template> 
<style> /*...*/ </style> 
<div id="label"><content></content></div> 
Value: <span id="counterVal">{{counter}}</span><br> 
<button on-tap="{{increment}}">Increment</button> 
</template> 
<script> 
Polymer({ 
counter: 0, // Default value 
counterChanged: function() { 
this.$.counterVal.classList.add('highlight'); 
}, 
increment: function() { 
this.counter++; 
} 
}); 
</script> 
</polymer-element>
encapsulation with the Shadow DOM
THANKS!

More Related Content

What's hot

How browser engines work?
How browser engines work?How browser engines work?
How browser engines work?
haricot
 
Basics of css and xhtml
Basics of css and xhtmlBasics of css and xhtml
Basics of css and xhtml
sagaroceanic11
 

What's hot (20)

OOCSS, SMACSS or BEM?
OOCSS, SMACSS or BEM?OOCSS, SMACSS or BEM?
OOCSS, SMACSS or BEM?
 
Learn SUIT: CSS Naming Convention
Learn SUIT: CSS Naming ConventionLearn SUIT: CSS Naming Convention
Learn SUIT: CSS Naming Convention
 
Bliblidotcom - Reintroduction BEM CSS
Bliblidotcom - Reintroduction BEM CSSBliblidotcom - Reintroduction BEM CSS
Bliblidotcom - Reintroduction BEM CSS
 
HTML CSS & Javascript
HTML CSS & JavascriptHTML CSS & Javascript
HTML CSS & Javascript
 
ActiveDOM
ActiveDOMActiveDOM
ActiveDOM
 
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
DRY CSS A don’t-repeat-yourself methodology for creating efficient, unified a...
 
CSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and moreCSS - OOCSS, SMACSS and more
CSS - OOCSS, SMACSS and more
 
Html & Css presentation
Html  & Css presentation Html  & Css presentation
Html & Css presentation
 
What is Object Oriented CSS?
What is Object Oriented CSS?What is Object Oriented CSS?
What is Object Oriented CSS?
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
Responsive & Responsible Web Design in DNN
Responsive & Responsible Web Design in DNNResponsive & Responsible Web Design in DNN
Responsive & Responsible Web Design in DNN
 
The Fast And The Fabulous
The Fast And The FabulousThe Fast And The Fabulous
The Fast And The Fabulous
 
What is Modular CSS?
What is Modular CSS?What is Modular CSS?
What is Modular CSS?
 
Responsive Websites
Responsive WebsitesResponsive Websites
Responsive Websites
 
Decoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSSDecoupling the Front-end with Modular CSS
Decoupling the Front-end with Modular CSS
 
Modern Front-End Development
Modern Front-End DevelopmentModern Front-End Development
Modern Front-End Development
 
How browser engines work?
How browser engines work?How browser engines work?
How browser engines work?
 
Fundamental CSS3
Fundamental CSS3Fundamental CSS3
Fundamental CSS3
 
Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...
Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...
Tip from ConnectED 2015: How to Use Those Cool New Frameworks in Mobile Domin...
 
Basics of css and xhtml
Basics of css and xhtmlBasics of css and xhtml
Basics of css and xhtml
 

Similar to BEM Methodology — @Frontenders Ticino —17/09/2014

CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
Itai Koren
 

Similar to BEM Methodology — @Frontenders Ticino —17/09/2014 (20)

Pfnp slides
Pfnp slidesPfnp slides
Pfnp slides
 
Build a better UI component library with Styled System
Build a better UI component library with Styled SystemBuild a better UI component library with Styled System
Build a better UI component library with Styled System
 
The Future is Modular, Jonathan Snook
The Future is Modular, Jonathan SnookThe Future is Modular, Jonathan Snook
The Future is Modular, Jonathan Snook
 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding Standards
 
Architecture for css
Architecture for cssArchitecture for css
Architecture for css
 
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSSObject-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
Object-Oriented CSS 從 OOCSS, SMACSS, BEM 到 AMCSS
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
Srijan presentation on CSS
Srijan presentation on CSSSrijan presentation on CSS
Srijan presentation on CSS
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
The Future State of Layout
The Future State of LayoutThe Future State of Layout
The Future State of Layout
 
CSS Workflow. Pre & Post
CSS Workflow. Pre & PostCSS Workflow. Pre & Post
CSS Workflow. Pre & Post
 
New css features
New css featuresNew css features
New css features
 
OOCSS, SMACSS or BEM, what is the question...
OOCSS, SMACSS or BEM, what is the question...OOCSS, SMACSS or BEM, what is the question...
OOCSS, SMACSS or BEM, what is the question...
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS Workshop
 
6 css week12 2020 2021 for g10
6 css week12 2020 2021 for g106 css week12 2020 2021 for g10
6 css week12 2020 2021 for g10
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
 
Rock Solid CSS Architecture
Rock Solid CSS ArchitectureRock Solid CSS Architecture
Rock Solid CSS Architecture
 
Css Systems
Css SystemsCss Systems
Css Systems
 
CSS framework By Palash
CSS framework By PalashCSS framework By Palash
CSS framework By Palash
 
SASS is more than LESS
SASS is more than LESSSASS is more than LESS
SASS is more than LESS
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

BEM Methodology — @Frontenders Ticino —17/09/2014

  • 1. BEM METHODOLOGY Vittorio Zaccaria September 17th, 2014
  • 2. ME Enthusiast about Javascript, CSS and Web technologies Looking forward to invest into promising swiss startups www.vittoriozaccaria.net vittorio.zaccaria@gmail.com
  • 3. WHAT YOU WILL GET FROM THIS SEMINAR
  • 4. understand how to deal with the complexity of your CSS (BEM)
  • 5. know which tools can help you manage your CSS projects
  • 6. a look at the future of front-end design technologies (web components)
  • 8. which selectors match a given element?
  • 9. .label .label.left .left .label.left CSS
  • 10. yup, it can become overwhelming
  • 11. .label .label.left.small .left .small .label.left .label.small .left.small .label.left.small CSS
  • 13. #a { background-color : blue; } .big.container > .b.c { background-color : red; } .big.container #a.b.c CSS
  • 14. #a { background-color : blue; } #a.b.c .big.container > .b.c { background-color : red; } .big.container CSS
  • 16. .header .header .logo .logo .header .logo
  • 17. cognitive load might mean waste of time and money in your team
  • 18. A MORE STRUCTURED APPROACH
  • 19. CSS Design CSS Engineering (Scientific Principles)
  • 21. HTML Project 2 Project 1 Code reuse HTML
  • 23. it’s a set of formalized guidelines developed by Yandex, RU in the past few years it is mainly a naming and structuring methodology for CSS/HTML
  • 24. How to define and structure modules for CSS, enabling separation How to of concerns and reuse organize files Tools for manipulating BEM compliant specs although it has more…
  • 25. BEM defines the concept of “block” for CSS we will call it also “component” or “module”
  • 26. block • html + style rules • independent w.r.t. other blocks • can be used in different parts/projects
  • 27.
  • 28.
  • 29.
  • 30. how BEM would define this block 1. use only one class - they flatten specificity 2. no positioning information in it 3. dont introduce relative adjustment
  • 31. .art-preview { width: 30%; ... } .art-preview CSS no parent blocks here, or we’d compromise reuse and mobility
  • 32. modifier changes a small amount of properties of a block it is another class to be added to the block itself
  • 33.
  • 34. .art-preview { width: 30%; } ! .art-preview__size_small { width: 15%; ... } ! .art-preview CSS .art-preview.art-preview__size_small
  • 35. name spacing for modifiers .art-preview__size_small Separator type of modification value of modification CSS
  • 36. modifiable through JS block(‘art-preview’).toggle(‘size_small’) adds/removes class JS
  • 37. element styles only a piece of a block this piece can’t live outside the block
  • 38.
  • 39. .art-preview element of .art-preview
  • 40. name spacing for elements .art-preview--title Separator name of the element CSS
  • 41. .art-preview { ... } ! .art-preview--title { font-size: 1.5rem; ... } .art-preview CSS .art-preview--title
  • 42.
  • 43. .art-preview--title { font-size: 1.5rem; ... } ! .art-preview__size_small .art-preview—title { font-size: 1.2rem; ... } .art-preview--title .art-preview__size_small .art-preview--title CSS
  • 44. .art-preview--title { font-size: 1.5rem; ... } ! .art-preview__size_small .art-preview—title { font-size: 1.2rem; ... } .art-preview--title .art-preview__size_small .art-preview--title CSS
  • 46.
  • 47.
  • 48. tab block .tab { ... } CSS
  • 49. tab block .tab { ... } ! .card { ... } CSS card block
  • 51. tab block .tab { ... } ! .card { ... } ! .tab .card { // set margins } CSS card block
  • 52. BEM
  • 53. tab block .tab { ... } ! .card { ... } ! .card.tab——card { // set margins } CSS card block not using generations to express nesting .card.tab--card
  • 54. child changes parent .form.form——has—modal .modal .form { ... } ! .modal { ... } ! .form.form——has—modal { // disable input } CSS
  • 58. use css preprocessors LESS .header { background: white; &——title { font: bold 24px/1 sans-serif; &__featured { font-size: 30px; } } } CSS .header { background: white; } .header——title { font: bold 24px/1 sans-serif; } .header——title__featured { font-size: 30px; } src: http://frontendbabel.info/articles/bem-with-css-preprocessors/
  • 59. BEMTO HTML src: https://github.com/kizu/bemto JADE +b.block1 +e.element1 Foo +b.block2 +e('a')(href="#bar").element Bar +e.element2 Baz <div class="block1"> <div class="block1__element1"> Foo </div> <div class="block2"> <a class="block2__element" href="#bar">Bar</a> </div> <div class="block1__element2"> Baz </div> </div>
  • 60. seriously, try jade, even without BEM http://jade-lang.com/
  • 61. WHAT ABOUT SMACSS - MVCSS?
  • 62. MVCSS BEM SMACSS block element modifier Scalable and modular CSS https://smacss.com/ base applies to tags and ids layout Nesting similar to grids and stuff modules subclassing states Modular View CSS http://mvcss.github.io/ foundation reset structures not reusable patterns components reusable patterns
  • 65. create your own tags! HTML <!-- Polyfill Web Components support for older browsers --> <script src="components/platform/platform.js"></script> ! <!-- Import element --> <link rel="import" href="counter.html"> ! <!-- Use element --> <my-counter counter="10">Points</my-counter>
  • 66. HTML <!-- Define element --> <polymer-element name="my-counter" attributes="counter"> <template> <style> /*...*/ </style> <div id="label"><content></content></div> Value: <span id="counterVal">{{counter}}</span><br> <button on-tap="{{increment}}">Increment</button> </template> <script> Polymer({ counter: 0, // Default value counterChanged: function() { this.$.counterVal.classList.add('highlight'); }, increment: function() { this.counter++; } }); </script> </polymer-element>