SlideShare ist ein Scribd-Unternehmen logo
1 von 55
Downloaden Sie, um offline zu lesen
The benefits of BEM 
CSS 
The benefits of BEM CSS - Bob Donderwinkel, 2014 1
Who? 
• Bob Donderwinkel 
• Front-end Developer at Viewbook 
• Freelancer at bd creations 
The benefits of BEM CSS - Bob Donderwinkel, 2014 2
Who? 
• Bob Donderwinkel 
• Front-end Developer at Viewbook 
Our hardheaded senior front-end developer, currently 
specialising in responsive HTML, CSS and mobile 
• Freelancer at bd creations 
The benefits of BEM CSS - Bob Donderwinkel, 2014 3
Who? 
• Bob Donderwinkel 
• Front-end Developer at Viewbook 
Our hardheaded senior front-end developer, currently 
specialising in responsive HTML, CSS and mobile 
• Freelancer at bd creations 
Development with Eye for Design 
The benefits of BEM CSS - Bob Donderwinkel, 2014 4
So what's the gist? 
• What is BEM? 
• What does BEM solve? 
• What have I used BEM for? 
• Some semi-interesting BEM tidbits 
The benefits of BEM CSS - Bob Donderwinkel, 2014 5
So what's the gist? 
• What is BEM? 
• What does BEM solve? 
• What have I used BEM for? 
• Some semi-interesting BEM tidbits 
Mind you, I have been working with BEM CSS for about half a 
year now. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 6
So what is BEM? 
The benefits of BEM CSS - Bob Donderwinkel, 2014 7
Block, Element, Modifier 
The benefits of BEM CSS - Bob Donderwinkel, 2014 8
So what is BEM? 
You might just as well call it 
Module, Object, Modifier 
But then you could be saying something like 
I am using MOM 
Which would be weird. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 9
Unified semantic model 
for markup, styles, code 
and UX 
— Smashing Magazine 
The benefits of BEM CSS - Bob Donderwinkel, 2014 10
What is BEM? 
• BEM originated at Yandex 
• BEM is a methodology, an abstract way of reasoning about 
your interface. 
• BEM captures purpose and meaning through it's CSS 
classname syntax. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 11
What is BEM? 
BEM is not just for CSS. It is about communicating between 
technologies and the people using them. 
• Design 
• Markup 
• Styles 
• Code 
The benefits of BEM CSS - Bob Donderwinkel, 2014 12
Block, Elements and Modifiers 
What is that about? 
The benefits of BEM CSS - Bob Donderwinkel, 2014 13
Block 
What is BEM? 
• An independent, reusable part of your interface. 
• Think: Headers, Menus, Images, etc 
• Can contain Elements and other Blocks. 
• Can contain one or more Modifiers 
<header class='b-header'> 
</header> 
The benefits of BEM CSS - Bob Donderwinkel, 2014 14
Element 
What is BEM? 
• Belongs to a Block, only has meaning there 
• Can contain other Elements and Blocks. 
• Think: Header sub-title, Menu item, Image caption, etc 
• Can contain one or more Modifiers 
<header class='b-header'> 
<h1 class='b-header__title'></h1> 
<p class='b-header__description'></p> 
</header> 
The benefits of BEM CSS - Bob Donderwinkel, 2014 15
Modifiers 
What is BEM? 
• Belongs on a Block or Element 
• Indicates a state different from the default 
• Think: themes, active/inactive state, aligning, etc 
• Can also be a key value pair 
<header class='b-header b-header_theme_awesome'> 
<h1 class='b-header__title b-header__title_large'></h1> 
<p class='b-header__description'></p> 
</header> 
The benefits of BEM CSS - Bob Donderwinkel, 2014 16
Modifiers 
What is BEM? 
And Modifiers are nicely groupable using CSS preprocessors 
like SASS/LESS 
.b-header{ 
&_theme_awesome{ 
background-color: PapayaWhip; 
} 
&__title { 
&_large{ 
font-size: xx-large; 
} 
} 
} 
The benefits of BEM CSS - Bob Donderwinkel, 2014 17
BEM CSS syntax 
What is BEM? 
The official syntax 
.b-[block-name] 
.b-[block-name]__[element] 
.b-[block-name]__[element]_[modifier] 
Pretty simple. 
- Use only Latin letters, dashes and digits. Not underscores (_) 
- Use underscores as the Block, Element and Modifier 
separators. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 18
BEM CSS syntax 
What is BEM? 
Is this okay? 
.b-[block-name]__[element]__[sub-element] 
.b-[block-name]_[modifier]__[element] 
I have seen some conflicting articles, but probably not. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 19
BEM CSS syntax 
What is BEM? 
Or roll your own syntax. 
Perhaps because that better suits the CSS code base of a 
project. In any case: 
• Be consistent 
• Keep the Block/Element/Modifier separators unique so you 
can use BEM automation tools. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 20
BEM CSS syntax 
So what is BEM? 
Most importantly, use meaningful BEM classnames. 
If you end up with something like this, it could pretty much 
defeat the point. 
.b-awesome-gizmo-three__teaser_latest 
The benefits of BEM CSS - Bob Donderwinkel, 2014 21
What is BEM? 
BEM also touches on some well known Object Oriented 
Programming concepts. 
Don't Repeat Yourself (DRY) 
- Blocks are self contained and reusable. 
Seperation of Concerns 
- Using BEM CSS classes decouples your CSS from your HTML. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 22
What is BEM? 
BEM also touches on some well known Object Oriented 
Programming concepts. 
Single Responsibility Principle 
- Blocks, Element and Modifiers focus on managing just one 
thing, themselves. 
Open/Closed Principle 
- Modifiers often only extend on default styles and behaviour 
The benefits of BEM CSS - Bob Donderwinkel, 2014 23
So what does BEM CSS solve? 
The benefits of BEM CSS - Bob Donderwinkel, 2014 24
Chaos (Greek χάοςm 
khaos) the formless or 
void state preceding the 
creation of .. (*) 
— * = insert title of your awesome project here 
The benefits of BEM CSS - Bob Donderwinkel, 2014 25
Seriously, what does using BEM CSS really help with? 
CSS can be wonderfully simple and easy to get started with. And 
even easier to mess up on the long run. 
Legacy CSS can be a royal pain. 
We have all been there, or have inherited these kind of 
projects to take care of. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 26
Seriously, what does using BEM CSS really help with? 
When projects scale, CSS often does not. 
CSS code is easy to append, overwrite or reinvent. That can 
turn in to a mess. 
It is a bit like growing a new haircut every month, but only 
trimming a piece of it. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 27
It is fun until you 
realise you can not 
walk away from it. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 28
So what does BEM CSS solve? 
BEM CSS gives you a default aproach for new projects. 
• Thinking in Blocks, Elements and Modifiers helps you figure 
out what your design is made of. 
• BEM helps you getting started coding CSS a little bit quicker 
through a standard syntax. 
• BEM is about communicating between technologies and 
the people using them. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 29
So what does BEM CSS solve? 
For example 
- Your design tells you what Blocks, Elements and Modifiers are present. 
- You can use these to scaffold up a rough prototype using HTML and CSS. 
- You review the prototype to see what behaviour is needed with Javascript. 
- The design is tweaked and the prototype is tuned. 
- Rinse and repeat. 
And you're done.. 
..Well at least you have a better idea what your project needs 
to complete ;) 
The benefits of BEM CSS - Bob Donderwinkel, 2014 30
Yes, yes.. Can you give me some 
pratical reasons to use BEM CSS 
The benefits of BEM CSS - Bob Donderwinkel, 2014 31
Is there any practical stuff BEM CSS can help with? 
What does BEM solve 
Single CSS classname perks 
Better CSS performance 
• Rendering engines evaluate CSS selectors right to left. 
• The less they have to evaluate, the faster it renders. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 32
Is there any practical stuff BEM CSS can help with? 
What does BEM solve 
My view is that authors should not need to worry about 
optimizing selectors (and from what I see, they generally don’t), 
that should be the job of the engine. 
~ Antti Koivisto 
Luckely CSS is the least of your performance worries today. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 33
Is there any practical stuff BEM CSS can help with? 
What does BEM solve 
Reduce hell in CSS specificty 
• Complex CSS selectors get a higher importance. You have 
to match up to this selector or use !important to override it. 
• Or find the actual CSS you want to change. But the bigger 
the CSS code base, the nastier that can get ;) 
Using single CSS classnames makes it easier to rework your 
existing CSS code base. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 34
Is there any practical stuff BEM CSS can help with? 
What does BEM solve 
Global CSS reset/normalize not needed (preferably) 
• Remember BEM Blocks should be independent and re-usable. 
A global CSS reset/normalize does not exactly fit 
that idea. 
Perhaps use something like uncss in your build process to get 
only the needed normalize/reset CSS into your Blocks and 
Elements. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 35
Is there any practical stuff BEM CSS can help with? 
What does BEM solve 
Better HTML/CSS decoupling 
• Using HTML element names in your CSS selectors forces 
you to update both when only one changes. 
• Using just single CSS BEM classnames makes them more 
portable to another HTML structure. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 36
Is there any practical stuff BEM CSS can help with? 
What does BEM solve 
Project automation through BEM's predictable CSS 
classnames 
• Yandex has tools if you are using the standard BEM syntax 
• CSS preprocessors like SASS and LESS are especially well 
suited for generating BEM CSS 
• And with build tools like Grunt or Gulp you can custom fit 
BEM CSS automation for your own project. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 37
But is it all utter BEM BLISS? 
The benefits of BEM CSS - Bob Donderwinkel, 2014 38
Utter BEM BLISS? 
What about the CSS cascade? 
Yes, using just single CSS classnames can feel a bit too 
simplistic at times. But you can use regular CSS allong with 
your BEM CSS. Or you can use SASS or LESS to @include or 
@extend a CSS library. 
@import "my-themes"; 
&_theme_awesome{ 
@include theme-more-awesome(); 
} 
The benefits of BEM CSS - Bob Donderwinkel, 2014 39
Utter BEM BLISS? 
But I hate looking at long and ugly-ish CSS classnames 
• True.. no way around that. BEM CSS can be a tad 
challenging for the aesthetically inclinded code fashionista. 
• But luckely the visitor of website or application will not look 
in the source all too often ;) 
Doesn't HTML filesize bloat with long CSS classnames? 
• Yes, true. But minification and gzipping go a long way. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 40
Utter BEM CSS BLISS? 
And is BEM only useful in larger teams? 
• BEM CSS certainly has extra perks in larger teams because 
of the meaningful BEM CSS classnames. 
• But working solo you can also use the Block, Element and 
Modifier approach on a design to get started prototyping 
sooner. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 41
Utter BEM CSS BLISS? 
Is BEM not yet another 'framework/methodology/ 
whatever' to try and get my head around? 
• Yes, but it's concept and syntax is pretty straight forward to 
get started with and use. 
• And BEM can play pretty nicely with other CSS approaches 
out there. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 42
Utter BEM BLISS? 
Other CSS approaches 
Object Oriented CSS 
• Separation of Structure from Skin 
• Separation of Containers and Content 
In essence OOCSS is about keeping CSS modular so it can be 
reused and extended. This is similar to the Block, Element and 
Modifier approach. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 43
Utter BEM BLISS? 
Other CSS approaches 
Scalable and Modular Architecture for CSS 
• Guidelines how you can write and organize your CSS 
SMACCS has five types of CSS categories Base, Layout, 
Module, State, Theme. 
The Module and State categories are simular analogue for the 
Block, Element and Modifier approach. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 44
Utter BEM BLISS? 
Other CSS approaches 
Web components 
- Polymer and Brick 
Web Components are a collection of web standards focussed 
on delivering self-contained and reusable custom blocks of 
HTML, Javascript & CSS. 
BEM CSS can be used 'inside' a Web Component just like in 
any other project, and with roughly the same benefits. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 45
Do you have some interesting 
BEM CSS tidbits? 
The benefits of BEM CSS - Bob Donderwinkel, 2014 46
Multi modifer CSS classes 
BEM tidbits 
Multi modifer CSS classes 
- Some Gulp.js which will rework a bit of BEM CSS so you can 
use multiple Modifiers in a single BEM class 
__block__element_theme-light_size-large 
Wow, even longer CSS classnames...! 
The benefits of BEM CSS - Bob Donderwinkel, 2014 47
Multi modifer CSS classes 
BEM tidbits 
@bobdonderwinkel we suggest to use classic approach and write 
as many classes as needed in DOM tree 
@bobdonderwinkel and avoid copypaste with the help of 
template engines 
— Twitter #b_ 
Yeah, perhaps not that great an idea afterall. Fun experiment 
though. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 48
kaBEM 
BEM tidbits 
BEM CSS scaffolding on some steroids 
kaBEM is a grunt.js environment for quick scaffolding and 
tweaking of HTML with BEM CSS (Block, Element, Modifier). 
- See a BEM classname in your CSS and know where to use it in your HTML 
- See a BEM classname in your HTML and know where to find it in your CSS files 
- See a BEM classname and know which purpose it has 
But.. Disclaimer 
The benefits of BEM CSS - Bob Donderwinkel, 2014 49
kaBEM 
BEM tidbits 
Disclaimer: I created kaBEM just starting with BEM CSS. So be 
mindful of some little hickups that trickeled in. For example 
kaBEM uses multi element/modifier BEM CSS classnames. 
.b-block__element-1__element-2 
.b-block__element_modifiers-1_modifier-2 
In hindsight these are a bit of a BEM CSS no-no ;) But no 
worries, a new version is on the way. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 50
BEM User Stories 
BEM tidbits 
User stories seem like a nice way to get going with BEM even 
before you get busy with a design or prototype. 
• Sum up what parts should be present (Blocks and Elements) 
• Describe how these parts should look & behave (Modifiers) 
• Translate these User Stories in BEM CSS classnames 
• Get some coffee and start coding 
The benefits of BEM CSS - Bob Donderwinkel, 2014 51
Okay, round up already 
The benefits of BEM CSS - Bob Donderwinkel, 2014 52
Rounding up 
• Thinking in Block, Elements and Modifiers helps you 
interpretate a design quicker and get you started coding 
sooner. 
• BEM CSS classnames are about communicating, keep them 
meaningful. 
• BEM CSS classnames are well suited for automation 
because of it's default syntax. 
The benefits of BEM CSS - Bob Donderwinkel, 2014 53
Good reads 
Rounding up 
• Scaling Down The BEM Methodology For Small Projects 
• MindBEMding – getting your head ’round BEM syntax 
• Organizing CSS: OOCSS, SMACSS, and BEM 
• Generating BEM selectors with CSS preprocessors 
The benefits of BEM CSS - Bob Donderwinkel, 2014 54
Contact me! 
Rounding up 
• www.bdcreations.nl 
• b.donderwinkel@bdcreations.nl 
• Twitter 
• Linkedin 
The benefits of BEM CSS - Bob Donderwinkel, 2014 55

Weitere ähnliche Inhalte

Was ist angesagt?

How to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS projectHow to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS project
Renoir Boulanger
 

Was ist angesagt? (20)

How to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS projectHow to manage a big scale HTML/CSS project
How to manage a big scale HTML/CSS project
 
Object Oriented CSS
Object Oriented CSSObject Oriented CSS
Object Oriented CSS
 
Front End Best Practices
Front End Best PracticesFront End Best Practices
Front End Best Practices
 
What is Object Oriented CSS?
What is Object Oriented CSS?What is Object Oriented CSS?
What is Object Oriented CSS?
 
Bliblidotcom - Reintroduction BEM CSS
Bliblidotcom - Reintroduction BEM CSSBliblidotcom - Reintroduction BEM CSS
Bliblidotcom - Reintroduction BEM CSS
 
Learn SUIT: CSS Naming Convention
Learn SUIT: CSS Naming ConventionLearn SUIT: CSS Naming Convention
Learn SUIT: CSS Naming Convention
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
A Deeper look into Javascript Basics
A Deeper look into Javascript BasicsA Deeper look into Javascript Basics
A Deeper look into Javascript Basics
 
0X0D - Responsive
0X0D - Responsive0X0D - Responsive
0X0D - Responsive
 
CSS Bloat!
CSS Bloat!CSS Bloat!
CSS Bloat!
 
Basic Html Notes
Basic Html NotesBasic Html Notes
Basic Html Notes
 
0x06-CSS-texto.pdf
0x06-CSS-texto.pdf0x06-CSS-texto.pdf
0x06-CSS-texto.pdf
 
CSS와 BEM
CSS와 BEMCSS와 BEM
CSS와 BEM
 
Introduction to BOOTSTRAP
Introduction to BOOTSTRAPIntroduction to BOOTSTRAP
Introduction to BOOTSTRAP
 
The Power of CSS Flexbox
The Power of CSS FlexboxThe Power of CSS Flexbox
The Power of CSS Flexbox
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
 
0x08-CSS-flexbox.pdf
0x08-CSS-flexbox.pdf0x08-CSS-flexbox.pdf
0x08-CSS-flexbox.pdf
 
Advanced Cascading Style Sheets
Advanced Cascading Style SheetsAdvanced Cascading Style Sheets
Advanced Cascading Style Sheets
 
SASS - CSS with Superpower
SASS - CSS with SuperpowerSASS - CSS with Superpower
SASS - CSS with Superpower
 

Andere mochten auch

Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEM
Varya Stepanova
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
Zohar Arad
 

Andere mochten auch (20)

BEM it!
BEM it!BEM it!
BEM it!
 
Bem presentation
Bem presentationBem presentation
Bem presentation
 
Maintainable Frontend Development with BEM
Maintainable Frontend Development with BEMMaintainable Frontend Development with BEM
Maintainable Frontend Development with BEM
 
Atomic design
Atomic designAtomic design
Atomic design
 
Using static analysis tools within continuous integration systems
Using static analysis tools within continuous integration systemsUsing static analysis tools within continuous integration systems
Using static analysis tools within continuous integration systems
 
Your CSS is Awesome
Your CSS is AwesomeYour CSS is Awesome
Your CSS is Awesome
 
What is Modular CSS?
What is Modular CSS?What is Modular CSS?
What is Modular CSS?
 
CSS3 Animations & Transitions with PhoneGap
CSS3 Animations & Transitions with PhoneGapCSS3 Animations & Transitions with PhoneGap
CSS3 Animations & Transitions with PhoneGap
 
10 Commandments for efficient CSS architecture [CSSConf.Asia '14]
10 Commandments for efficient CSS architecture [CSSConf.Asia '14]10 Commandments for efficient CSS architecture [CSSConf.Asia '14]
10 Commandments for efficient CSS architecture [CSSConf.Asia '14]
 
BEM methodology overview
BEM methodology overviewBEM methodology overview
BEM methodology overview
 
CSS Selectors
CSS SelectorsCSS Selectors
CSS Selectors
 
Color schemes
Color schemesColor schemes
Color schemes
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
 
Odnaleźć się w nanokosmosie
Odnaleźć się w nanokosmosieOdnaleźć się w nanokosmosie
Odnaleźć się w nanokosmosie
 
Architecting single-page front-end apps
Architecting single-page front-end appsArchitecting single-page front-end apps
Architecting single-page front-end apps
 
실전 Html5 guide
실전 Html5 guide실전 Html5 guide
실전 Html5 guide
 
October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101October 2014 - USG Rock Eagle - Sass 101
October 2014 - USG Rock Eagle - Sass 101
 
BEVM ( block__element--variation -modifier)
BEVM ( block__element--variation -modifier)BEVM ( block__element--variation -modifier)
BEVM ( block__element--variation -modifier)
 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tips
 
6 Steps to Make Your CSS Code More Maintainable
6 Steps to Make Your CSS Code More Maintainable6 Steps to Make Your CSS Code More Maintainable
6 Steps to Make Your CSS Code More Maintainable
 

Ähnlich wie The benefits of BEM CSS

WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
New Tricks
 
Web Design & UI/UX Bootcamp [Online & Offline] In Bangla
Web Design & UI/UX Bootcamp [Online & Offline] In BanglaWeb Design & UI/UX Bootcamp [Online & Offline] In Bangla
Web Design & UI/UX Bootcamp [Online & Offline] In Bangla
Stack Learner
 
Developing branding solutions
Developing branding solutionsDeveloping branding solutions
Developing branding solutions
Thomas Daly
 
Web programming css
Web programming cssWeb programming css
Web programming css
Uma mohan
 

Ähnlich wie The benefits of BEM CSS (20)

Php Indonesia x Bliblidotcom - Architecting Scalable CSS
Php Indonesia x Bliblidotcom - Architecting Scalable CSSPhp Indonesia x Bliblidotcom - Architecting Scalable CSS
Php Indonesia x Bliblidotcom - Architecting Scalable CSS
 
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
Scalable front-end architecture with Bootstrap 3 + Atomic CSSScalable front-end architecture with Bootstrap 3 + Atomic CSS
Scalable front-end architecture with Bootstrap 3 + Atomic CSS
 
Creating a Business Oriented UI in APEX
Creating a Business Oriented UI in APEXCreating a Business Oriented UI in APEX
Creating a Business Oriented UI in APEX
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSSStructuring your CSS for maintainability: rules and guile lines to write CSS
Structuring your CSS for maintainability: rules and guile lines to write CSS
 
Mixing Business and WordPress for Fun and Profit
Mixing Business and WordPress for Fun and ProfitMixing Business and WordPress for Fun and Profit
Mixing Business and WordPress for Fun and Profit
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 
Know the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css frameworkKnow the reason behind choosing bootstrap as css framework
Know the reason behind choosing bootstrap as css framework
 
Getting Started With WordPress Themes for Beginners
Getting Started With WordPress Themes for BeginnersGetting Started With WordPress Themes for Beginners
Getting Started With WordPress Themes for Beginners
 
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by StepBootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
Bootstrap 4 Tutorial PDF for Beginners - Learn Step by Step
 
Customizing WordPress Themes
Customizing WordPress ThemesCustomizing WordPress Themes
Customizing WordPress Themes
 
How To Choose A Theme
How To Choose A ThemeHow To Choose A Theme
How To Choose A Theme
 
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
WordCamp Atlanta 2014 - CSS For Beginners - By Michael Earley of ATL Squared ...
 
css and wordpress
css and wordpresscss and wordpress
css and wordpress
 
css and wordpress
css and wordpresscss and wordpress
css and wordpress
 
Web Design & UI/UX Bootcamp [Online & Offline] In Bangla
Web Design & UI/UX Bootcamp [Online & Offline] In BanglaWeb Design & UI/UX Bootcamp [Online & Offline] In Bangla
Web Design & UI/UX Bootcamp [Online & Offline] In Bangla
 
Things you can do to brand Office 365 now
Things you can do to brand Office 365 nowThings you can do to brand Office 365 now
Things you can do to brand Office 365 now
 
Smash.wordpress
Smash.wordpressSmash.wordpress
Smash.wordpress
 
Developing branding solutions
Developing branding solutionsDeveloping branding solutions
Developing branding solutions
 
Web programming css
Web programming cssWeb programming css
Web programming css
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

The benefits of BEM CSS

  • 1. The benefits of BEM CSS The benefits of BEM CSS - Bob Donderwinkel, 2014 1
  • 2. Who? • Bob Donderwinkel • Front-end Developer at Viewbook • Freelancer at bd creations The benefits of BEM CSS - Bob Donderwinkel, 2014 2
  • 3. Who? • Bob Donderwinkel • Front-end Developer at Viewbook Our hardheaded senior front-end developer, currently specialising in responsive HTML, CSS and mobile • Freelancer at bd creations The benefits of BEM CSS - Bob Donderwinkel, 2014 3
  • 4. Who? • Bob Donderwinkel • Front-end Developer at Viewbook Our hardheaded senior front-end developer, currently specialising in responsive HTML, CSS and mobile • Freelancer at bd creations Development with Eye for Design The benefits of BEM CSS - Bob Donderwinkel, 2014 4
  • 5. So what's the gist? • What is BEM? • What does BEM solve? • What have I used BEM for? • Some semi-interesting BEM tidbits The benefits of BEM CSS - Bob Donderwinkel, 2014 5
  • 6. So what's the gist? • What is BEM? • What does BEM solve? • What have I used BEM for? • Some semi-interesting BEM tidbits Mind you, I have been working with BEM CSS for about half a year now. The benefits of BEM CSS - Bob Donderwinkel, 2014 6
  • 7. So what is BEM? The benefits of BEM CSS - Bob Donderwinkel, 2014 7
  • 8. Block, Element, Modifier The benefits of BEM CSS - Bob Donderwinkel, 2014 8
  • 9. So what is BEM? You might just as well call it Module, Object, Modifier But then you could be saying something like I am using MOM Which would be weird. The benefits of BEM CSS - Bob Donderwinkel, 2014 9
  • 10. Unified semantic model for markup, styles, code and UX — Smashing Magazine The benefits of BEM CSS - Bob Donderwinkel, 2014 10
  • 11. What is BEM? • BEM originated at Yandex • BEM is a methodology, an abstract way of reasoning about your interface. • BEM captures purpose and meaning through it's CSS classname syntax. The benefits of BEM CSS - Bob Donderwinkel, 2014 11
  • 12. What is BEM? BEM is not just for CSS. It is about communicating between technologies and the people using them. • Design • Markup • Styles • Code The benefits of BEM CSS - Bob Donderwinkel, 2014 12
  • 13. Block, Elements and Modifiers What is that about? The benefits of BEM CSS - Bob Donderwinkel, 2014 13
  • 14. Block What is BEM? • An independent, reusable part of your interface. • Think: Headers, Menus, Images, etc • Can contain Elements and other Blocks. • Can contain one or more Modifiers <header class='b-header'> </header> The benefits of BEM CSS - Bob Donderwinkel, 2014 14
  • 15. Element What is BEM? • Belongs to a Block, only has meaning there • Can contain other Elements and Blocks. • Think: Header sub-title, Menu item, Image caption, etc • Can contain one or more Modifiers <header class='b-header'> <h1 class='b-header__title'></h1> <p class='b-header__description'></p> </header> The benefits of BEM CSS - Bob Donderwinkel, 2014 15
  • 16. Modifiers What is BEM? • Belongs on a Block or Element • Indicates a state different from the default • Think: themes, active/inactive state, aligning, etc • Can also be a key value pair <header class='b-header b-header_theme_awesome'> <h1 class='b-header__title b-header__title_large'></h1> <p class='b-header__description'></p> </header> The benefits of BEM CSS - Bob Donderwinkel, 2014 16
  • 17. Modifiers What is BEM? And Modifiers are nicely groupable using CSS preprocessors like SASS/LESS .b-header{ &_theme_awesome{ background-color: PapayaWhip; } &__title { &_large{ font-size: xx-large; } } } The benefits of BEM CSS - Bob Donderwinkel, 2014 17
  • 18. BEM CSS syntax What is BEM? The official syntax .b-[block-name] .b-[block-name]__[element] .b-[block-name]__[element]_[modifier] Pretty simple. - Use only Latin letters, dashes and digits. Not underscores (_) - Use underscores as the Block, Element and Modifier separators. The benefits of BEM CSS - Bob Donderwinkel, 2014 18
  • 19. BEM CSS syntax What is BEM? Is this okay? .b-[block-name]__[element]__[sub-element] .b-[block-name]_[modifier]__[element] I have seen some conflicting articles, but probably not. The benefits of BEM CSS - Bob Donderwinkel, 2014 19
  • 20. BEM CSS syntax What is BEM? Or roll your own syntax. Perhaps because that better suits the CSS code base of a project. In any case: • Be consistent • Keep the Block/Element/Modifier separators unique so you can use BEM automation tools. The benefits of BEM CSS - Bob Donderwinkel, 2014 20
  • 21. BEM CSS syntax So what is BEM? Most importantly, use meaningful BEM classnames. If you end up with something like this, it could pretty much defeat the point. .b-awesome-gizmo-three__teaser_latest The benefits of BEM CSS - Bob Donderwinkel, 2014 21
  • 22. What is BEM? BEM also touches on some well known Object Oriented Programming concepts. Don't Repeat Yourself (DRY) - Blocks are self contained and reusable. Seperation of Concerns - Using BEM CSS classes decouples your CSS from your HTML. The benefits of BEM CSS - Bob Donderwinkel, 2014 22
  • 23. What is BEM? BEM also touches on some well known Object Oriented Programming concepts. Single Responsibility Principle - Blocks, Element and Modifiers focus on managing just one thing, themselves. Open/Closed Principle - Modifiers often only extend on default styles and behaviour The benefits of BEM CSS - Bob Donderwinkel, 2014 23
  • 24. So what does BEM CSS solve? The benefits of BEM CSS - Bob Donderwinkel, 2014 24
  • 25. Chaos (Greek χάοςm khaos) the formless or void state preceding the creation of .. (*) — * = insert title of your awesome project here The benefits of BEM CSS - Bob Donderwinkel, 2014 25
  • 26. Seriously, what does using BEM CSS really help with? CSS can be wonderfully simple and easy to get started with. And even easier to mess up on the long run. Legacy CSS can be a royal pain. We have all been there, or have inherited these kind of projects to take care of. The benefits of BEM CSS - Bob Donderwinkel, 2014 26
  • 27. Seriously, what does using BEM CSS really help with? When projects scale, CSS often does not. CSS code is easy to append, overwrite or reinvent. That can turn in to a mess. It is a bit like growing a new haircut every month, but only trimming a piece of it. The benefits of BEM CSS - Bob Donderwinkel, 2014 27
  • 28. It is fun until you realise you can not walk away from it. The benefits of BEM CSS - Bob Donderwinkel, 2014 28
  • 29. So what does BEM CSS solve? BEM CSS gives you a default aproach for new projects. • Thinking in Blocks, Elements and Modifiers helps you figure out what your design is made of. • BEM helps you getting started coding CSS a little bit quicker through a standard syntax. • BEM is about communicating between technologies and the people using them. The benefits of BEM CSS - Bob Donderwinkel, 2014 29
  • 30. So what does BEM CSS solve? For example - Your design tells you what Blocks, Elements and Modifiers are present. - You can use these to scaffold up a rough prototype using HTML and CSS. - You review the prototype to see what behaviour is needed with Javascript. - The design is tweaked and the prototype is tuned. - Rinse and repeat. And you're done.. ..Well at least you have a better idea what your project needs to complete ;) The benefits of BEM CSS - Bob Donderwinkel, 2014 30
  • 31. Yes, yes.. Can you give me some pratical reasons to use BEM CSS The benefits of BEM CSS - Bob Donderwinkel, 2014 31
  • 32. Is there any practical stuff BEM CSS can help with? What does BEM solve Single CSS classname perks Better CSS performance • Rendering engines evaluate CSS selectors right to left. • The less they have to evaluate, the faster it renders. The benefits of BEM CSS - Bob Donderwinkel, 2014 32
  • 33. Is there any practical stuff BEM CSS can help with? What does BEM solve My view is that authors should not need to worry about optimizing selectors (and from what I see, they generally don’t), that should be the job of the engine. ~ Antti Koivisto Luckely CSS is the least of your performance worries today. The benefits of BEM CSS - Bob Donderwinkel, 2014 33
  • 34. Is there any practical stuff BEM CSS can help with? What does BEM solve Reduce hell in CSS specificty • Complex CSS selectors get a higher importance. You have to match up to this selector or use !important to override it. • Or find the actual CSS you want to change. But the bigger the CSS code base, the nastier that can get ;) Using single CSS classnames makes it easier to rework your existing CSS code base. The benefits of BEM CSS - Bob Donderwinkel, 2014 34
  • 35. Is there any practical stuff BEM CSS can help with? What does BEM solve Global CSS reset/normalize not needed (preferably) • Remember BEM Blocks should be independent and re-usable. A global CSS reset/normalize does not exactly fit that idea. Perhaps use something like uncss in your build process to get only the needed normalize/reset CSS into your Blocks and Elements. The benefits of BEM CSS - Bob Donderwinkel, 2014 35
  • 36. Is there any practical stuff BEM CSS can help with? What does BEM solve Better HTML/CSS decoupling • Using HTML element names in your CSS selectors forces you to update both when only one changes. • Using just single CSS BEM classnames makes them more portable to another HTML structure. The benefits of BEM CSS - Bob Donderwinkel, 2014 36
  • 37. Is there any practical stuff BEM CSS can help with? What does BEM solve Project automation through BEM's predictable CSS classnames • Yandex has tools if you are using the standard BEM syntax • CSS preprocessors like SASS and LESS are especially well suited for generating BEM CSS • And with build tools like Grunt or Gulp you can custom fit BEM CSS automation for your own project. The benefits of BEM CSS - Bob Donderwinkel, 2014 37
  • 38. But is it all utter BEM BLISS? The benefits of BEM CSS - Bob Donderwinkel, 2014 38
  • 39. Utter BEM BLISS? What about the CSS cascade? Yes, using just single CSS classnames can feel a bit too simplistic at times. But you can use regular CSS allong with your BEM CSS. Or you can use SASS or LESS to @include or @extend a CSS library. @import "my-themes"; &_theme_awesome{ @include theme-more-awesome(); } The benefits of BEM CSS - Bob Donderwinkel, 2014 39
  • 40. Utter BEM BLISS? But I hate looking at long and ugly-ish CSS classnames • True.. no way around that. BEM CSS can be a tad challenging for the aesthetically inclinded code fashionista. • But luckely the visitor of website or application will not look in the source all too often ;) Doesn't HTML filesize bloat with long CSS classnames? • Yes, true. But minification and gzipping go a long way. The benefits of BEM CSS - Bob Donderwinkel, 2014 40
  • 41. Utter BEM CSS BLISS? And is BEM only useful in larger teams? • BEM CSS certainly has extra perks in larger teams because of the meaningful BEM CSS classnames. • But working solo you can also use the Block, Element and Modifier approach on a design to get started prototyping sooner. The benefits of BEM CSS - Bob Donderwinkel, 2014 41
  • 42. Utter BEM CSS BLISS? Is BEM not yet another 'framework/methodology/ whatever' to try and get my head around? • Yes, but it's concept and syntax is pretty straight forward to get started with and use. • And BEM can play pretty nicely with other CSS approaches out there. The benefits of BEM CSS - Bob Donderwinkel, 2014 42
  • 43. Utter BEM BLISS? Other CSS approaches Object Oriented CSS • Separation of Structure from Skin • Separation of Containers and Content In essence OOCSS is about keeping CSS modular so it can be reused and extended. This is similar to the Block, Element and Modifier approach. The benefits of BEM CSS - Bob Donderwinkel, 2014 43
  • 44. Utter BEM BLISS? Other CSS approaches Scalable and Modular Architecture for CSS • Guidelines how you can write and organize your CSS SMACCS has five types of CSS categories Base, Layout, Module, State, Theme. The Module and State categories are simular analogue for the Block, Element and Modifier approach. The benefits of BEM CSS - Bob Donderwinkel, 2014 44
  • 45. Utter BEM BLISS? Other CSS approaches Web components - Polymer and Brick Web Components are a collection of web standards focussed on delivering self-contained and reusable custom blocks of HTML, Javascript & CSS. BEM CSS can be used 'inside' a Web Component just like in any other project, and with roughly the same benefits. The benefits of BEM CSS - Bob Donderwinkel, 2014 45
  • 46. Do you have some interesting BEM CSS tidbits? The benefits of BEM CSS - Bob Donderwinkel, 2014 46
  • 47. Multi modifer CSS classes BEM tidbits Multi modifer CSS classes - Some Gulp.js which will rework a bit of BEM CSS so you can use multiple Modifiers in a single BEM class __block__element_theme-light_size-large Wow, even longer CSS classnames...! The benefits of BEM CSS - Bob Donderwinkel, 2014 47
  • 48. Multi modifer CSS classes BEM tidbits @bobdonderwinkel we suggest to use classic approach and write as many classes as needed in DOM tree @bobdonderwinkel and avoid copypaste with the help of template engines — Twitter #b_ Yeah, perhaps not that great an idea afterall. Fun experiment though. The benefits of BEM CSS - Bob Donderwinkel, 2014 48
  • 49. kaBEM BEM tidbits BEM CSS scaffolding on some steroids kaBEM is a grunt.js environment for quick scaffolding and tweaking of HTML with BEM CSS (Block, Element, Modifier). - See a BEM classname in your CSS and know where to use it in your HTML - See a BEM classname in your HTML and know where to find it in your CSS files - See a BEM classname and know which purpose it has But.. Disclaimer The benefits of BEM CSS - Bob Donderwinkel, 2014 49
  • 50. kaBEM BEM tidbits Disclaimer: I created kaBEM just starting with BEM CSS. So be mindful of some little hickups that trickeled in. For example kaBEM uses multi element/modifier BEM CSS classnames. .b-block__element-1__element-2 .b-block__element_modifiers-1_modifier-2 In hindsight these are a bit of a BEM CSS no-no ;) But no worries, a new version is on the way. The benefits of BEM CSS - Bob Donderwinkel, 2014 50
  • 51. BEM User Stories BEM tidbits User stories seem like a nice way to get going with BEM even before you get busy with a design or prototype. • Sum up what parts should be present (Blocks and Elements) • Describe how these parts should look & behave (Modifiers) • Translate these User Stories in BEM CSS classnames • Get some coffee and start coding The benefits of BEM CSS - Bob Donderwinkel, 2014 51
  • 52. Okay, round up already The benefits of BEM CSS - Bob Donderwinkel, 2014 52
  • 53. Rounding up • Thinking in Block, Elements and Modifiers helps you interpretate a design quicker and get you started coding sooner. • BEM CSS classnames are about communicating, keep them meaningful. • BEM CSS classnames are well suited for automation because of it's default syntax. The benefits of BEM CSS - Bob Donderwinkel, 2014 53
  • 54. Good reads Rounding up • Scaling Down The BEM Methodology For Small Projects • MindBEMding – getting your head ’round BEM syntax • Organizing CSS: OOCSS, SMACSS, and BEM • Generating BEM selectors with CSS preprocessors The benefits of BEM CSS - Bob Donderwinkel, 2014 54
  • 55. Contact me! Rounding up • www.bdcreations.nl • b.donderwinkel@bdcreations.nl • Twitter • Linkedin The benefits of BEM CSS - Bob Donderwinkel, 2014 55