Writing Scalable
and Maintainable
CSS
Guude
wiie?
I am Dmitry Sheiko
a web developer, blogger, open
source contributor.
www.dsheiko.com
github.com/dsheiko
@sheiko
2
“
The skills required to write good
CSS code are by and large the
same skills required to write
good code in general.
Lea Verou
3
What are we after?
E.g. a button can be taken
from one context and
placed in other
5
Reusable
styles
Location
Independence
/* Tight coupling */
.callout a {}
/* Loose coupling */
.btn {}
6
Portability /* Context dependent */
.error { color: red; }
div.error { border: … }
<div class=“error”>Msg..</div>
/* Portable */
.error-txt { color: red; }
.error-box { border: … }
<div class=“error-txt error-
box”>Msg..</div>
7
Qualified
Selectors
/* Tight coupling */
ul.nav {}
a.button {}
div.header {}
/* Loose coupling */
.nav {}
.button {}
.header {}8
Use the cascade
carefully, scope the
classes, keep compoents
OCP, use composition
over inheritance
9
Conflict-free
styles
Loose class
names
/* Obscure selector intent,
chance of being accidently
redefined */
.card {}
/* Clear selector intent,
isolated scope*/
. credit-card-image {}
10
Content-Based
Class Names
/* Risk of becoming obsolete
*/
.red { color: red; }
/* Too specific, not reusable */
.header-color { color: red; }
/* Nicely abstracted and
portable */
.danger-color { color: red; }11
Function-
Based Class
Names
/* Makes it dependent to
markup */
. flex-columns {
flex-flow: column nowrap;
}
/* Bound to domain, not to
function */
.panel-content { .. }
12
Selector
Performance
/* Slower – reading from right
to left */
body.home div.header ul {}
/* Faster */
.primary-nav {}
13
Specificity /* Conflicting styles */
.foo .bar .label { color: red; }
.bar.baz .label { color: green; }
/* Will it be green or red?! */
. <div class="foo">
<div class="bar baz">
<label class="label">LABEL</label>
</div>
</div>14
Reactive
!important
/* Reactively used, brute-
force, specificity conflicts */
. heading-sub { font-size: 1.5em
!important; }
/* Proactively used */
.is-hidden { display: none
!important; }
15
References ▫Code smells in CSS
http://csswizardry.com/2012/11/code-
smells-in-css
▫ High-level advice and guidelines for
writing sane, manageable, scalable CSS
http://cssguidelin.es
▫10 things to need to know about CSS
http://dsheiko.com/weblog/10-things-to-
need-to-know-about-css/
16
Is there a
standardized
approach?
17
18
OOCSS
SMACSS
SUITCSS
Atomic
BEM
19
OOCSS SMACSS BEM
PCSS
https://github.com/dsheiko/pcss
Layers
20
Theme
Layout
Component
Element
State
Components
Component is a reusable
module of UI (e.g. nav-bar,
main-panel). Component
consists of elements (e.g.
main-panel __title) and can
be extended by subclasses
(e.g. nav-bar—primary)
21
Element
.foo__baz
Component
.foo
Subclass
.foo--bar
1
*
Abstract
button
component
<a class=“btn btn--primary”>
<i class=“btn__toolbar”>…</i>
Click me
</a>
22
Concrete
button
component
Toolbar element
component
State
State classes are
intended to represent a
UI unit state: .is-
expanded, .is-hidden,
.has-error.
23
<div class="l-main has-error">
<aside class="sidebar is-hidden">...</aside>
</div>
State
24
State
Layouts
Layout specifies how the
components are
arranged in a given
context (e.g. .l-app)
25
Layout
element
<div class="l-app">
<div class="l-app__body">
<aside class="l-app__aside">..</aside>
<div class="l-app__main">..</div>
</div>
</div>
26
Layout
Themes
Theme classes used to
alternate the style of a
component or a layout
depending on the
context. (e.g. .foo-
theme)
27
<html class="theme-foo">
<div class="l-main">
<aside class="sidebar">...</aside>
</div>
</html>
Themed
component
28
Theme
File Structure
29
References PCSS
https://github.com/dsheiko/pcss
BEM
http://getbem.com
OOCSS
https://oocss.org
SMACSS
https://smacss.com
ATOMIC
https://github.com/nemophrost/atomic-
css30
31
THANKS Any questions?
You can find me at
▫ www.dsheiko.com
▫ github.com/dsheiko
▫ @sheiko
CREDITS Special thanks to all the people who
made and released these awesome
resources for free:
▫ Presentation template by
SlidesCarnival
▫ Photographs by Unsplash
32

More Related Content

PPTX
Introduction to CSS3
PDF
Passing a Front end Developer interview
PDF
How to use CSS3 in WordPress
PPTX
learning to love html and css
PDF
10 tips to improve the usability of Joomla - Joomla World Conference 2014
PPTX
Lesson 3
PDF
Pemrograman Web 4 - Bootstrap 3
PPTX
[Final Presentation] Tiny Online Contests
Introduction to CSS3
Passing a Front end Developer interview
How to use CSS3 in WordPress
learning to love html and css
10 tips to improve the usability of Joomla - Joomla World Conference 2014
Lesson 3
Pemrograman Web 4 - Bootstrap 3
[Final Presentation] Tiny Online Contests

What's hot (13)

PDF
Maintainable Frontend Development with BEM
PDF
VT2019 - DA355A - Responsiv webbutveckling
PDF
Introduction to Twitter Bootstrap 3.0.3
PPTX
Web components. Compose the web.
PDF
CSS Audits: Take Back Control of your CSS (Susan Robertson)
PDF
PodsCMS Framework by Tom Hermans (WordCampNL)
PPT
Progressive Enhancement
PPTX
KnockoutJS: Web Dev Bliss
PDF
#4 - CSS Selectors, CSS3 and Web typography
PPTX
Javascript inside Browser (DOM)
PDF
Web Design Fundamentals
PDF
Creative Web 01 - Introduction to the web & web development
PDF
Leksion 1 hyrje ne xhtml
Maintainable Frontend Development with BEM
VT2019 - DA355A - Responsiv webbutveckling
Introduction to Twitter Bootstrap 3.0.3
Web components. Compose the web.
CSS Audits: Take Back Control of your CSS (Susan Robertson)
PodsCMS Framework by Tom Hermans (WordCampNL)
Progressive Enhancement
KnockoutJS: Web Dev Bliss
#4 - CSS Selectors, CSS3 and Web typography
Javascript inside Browser (DOM)
Web Design Fundamentals
Creative Web 01 - Introduction to the web & web development
Leksion 1 hyrje ne xhtml
Ad

Viewers also liked (7)

PPT
Requirement phase testing
PPT
Reliabilty
PPTX
Smacss and bem
PDF
Smacss e-css-faz-bem
PPT
Software quality
PPT
Test Life Cycle
PPTX
Quality Assurance and Software Testing
Requirement phase testing
Reliabilty
Smacss and bem
Smacss e-css-faz-bem
Software quality
Test Life Cycle
Quality Assurance and Software Testing
Ad

Similar to Writing Scalable and Maintainable CSS (20)

PDF
CSS Architecture - JSIL.pdf
PPT
Using a CSS Framework
PDF
How to use CSS3 in WordPress - Sacramento
PDF
Bootstrap Workout 2015
PDF
Front-End Methodologies
PPT
6 css week12 2020 2021 for g10
PPT
CSS Methodology
PPTX
CSS Architecture: Writing Maintainable CSS
PDF
9- Learn CSS Fundamentals / Pseudo-classes
PDF
Kohana 3.2 documentation
PDF
Teams, styles and scalable applications
PDF
Jina bolton - Refactoring Web Interfaces
PPTX
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
PDF
Do more with {less}
PDF
Does my DIV look big in this?
PDF
Front End Craftsmanship
PDF
Writing Readable Code
PPT
CSS előfeldolgozók
PDF
One Div To Save Them All: Controlling Drupal Div's and Implementing a Modular...
PDF
IV - CSS architecture
CSS Architecture - JSIL.pdf
Using a CSS Framework
How to use CSS3 in WordPress - Sacramento
Bootstrap Workout 2015
Front-End Methodologies
6 css week12 2020 2021 for g10
CSS Methodology
CSS Architecture: Writing Maintainable CSS
9- Learn CSS Fundamentals / Pseudo-classes
Kohana 3.2 documentation
Teams, styles and scalable applications
Jina bolton - Refactoring Web Interfaces
The New UI - Staying Strong with Flexbox, SASS, and {{Mustache.js}}
Do more with {less}
Does my DIV look big in this?
Front End Craftsmanship
Writing Readable Code
CSS előfeldolgozók
One Div To Save Them All: Controlling Drupal Div's and Implementing a Modular...
IV - CSS architecture

More from Dmitry Sheiko (7)

PPTX
The Flavor of TypeScript
PDF
Tooling JavaScript to ensure consistency in coding style
PDF
JavaScript MV* Framework - Making the Right Choice
PDF
Modular JavaScript with CommonJS Compiler
PDF
TypeScript Introduction
PDF
A Quick Start - Version Control with Git
PPTX
Bringing classical OOP into JavaScript
The Flavor of TypeScript
Tooling JavaScript to ensure consistency in coding style
JavaScript MV* Framework - Making the Right Choice
Modular JavaScript with CommonJS Compiler
TypeScript Introduction
A Quick Start - Version Control with Git
Bringing classical OOP into JavaScript

Recently uploaded (20)

PPTX
Partner to Customer - Sales Presentation_V23.01.pptx
PPTX
Networking2-LECTURE2 this is our lessons
DOCX
Audio to Video AI Technology Revolutiona
PDF
How Technology Shapes Our Information Age
PDF
Lesson.-Reporting-and-Sharing-of-Findings.pdf
PPTX
Introduction: Living in the IT ERA.pptx
PPTX
Going_to_Greece presentation Greek mythology
PPT
Expect The Impossiblesssssssssssssss.ppt
PPTX
Digital Project Mastery using Autodesk Docs Workshops
DOCX
MLS 113 Medical Parasitology (LECTURE).docx
PPTX
IoT Lecture IoT Lecture IoT Lecture IoT Lecture
PPSX
AI AppSec Threats and Defenses 20250822.ppsx
PPTX
WEEK 15.pptx WEEK 15.pptx WEEK 15.pptx WEEK 15.pptx
PPT
chapter 5: system unit computing essentials
PPTX
National-Historical-Commission-of-the-PhilippinesNHCP.pptx
PDF
Slides World Games Great Redesign Eco Economic Epochs.pdf
PPTX
REE IN CARBONATITE EEPOSIT AND INCLUDE CASE STUDY ON AMBADUNGAR
PDF
ilide.info-huawei-odn-solution-introduction-pdf-pr_a17152ead66ea2617ffbd01e8c...
PPTX
Concepts of Object Oriented Programming.
PPTX
购买林肯大学毕业证|i20Lincoln成绩单GPA修改本科毕业证书购买学历认证
Partner to Customer - Sales Presentation_V23.01.pptx
Networking2-LECTURE2 this is our lessons
Audio to Video AI Technology Revolutiona
How Technology Shapes Our Information Age
Lesson.-Reporting-and-Sharing-of-Findings.pdf
Introduction: Living in the IT ERA.pptx
Going_to_Greece presentation Greek mythology
Expect The Impossiblesssssssssssssss.ppt
Digital Project Mastery using Autodesk Docs Workshops
MLS 113 Medical Parasitology (LECTURE).docx
IoT Lecture IoT Lecture IoT Lecture IoT Lecture
AI AppSec Threats and Defenses 20250822.ppsx
WEEK 15.pptx WEEK 15.pptx WEEK 15.pptx WEEK 15.pptx
chapter 5: system unit computing essentials
National-Historical-Commission-of-the-PhilippinesNHCP.pptx
Slides World Games Great Redesign Eco Economic Epochs.pdf
REE IN CARBONATITE EEPOSIT AND INCLUDE CASE STUDY ON AMBADUNGAR
ilide.info-huawei-odn-solution-introduction-pdf-pr_a17152ead66ea2617ffbd01e8c...
Concepts of Object Oriented Programming.
购买林肯大学毕业证|i20Lincoln成绩单GPA修改本科毕业证书购买学历认证

Writing Scalable and Maintainable CSS