SlideShare a Scribd company logo
TAMING SELECTORS
   sanity for our stylesheets
SIZE OF THE CSS FILE AND
 IMPLIED HTTP REQUESTS
   are the biggest factor for CSS performance
REFLOWS AND
RENDERING TIME
  are (much!) less important
DUPLICATION IS WORSE
  THAN STALE RULES
  because we have tools to deal with the later
DEFINE DEFAULT VALUES
   Don’t repeat this code in every object
#weatherModule h3{color:red;}
#tabs h3{color:blue}




 DEFINE DEFAULT VALUES
       Don’t repeat this code in every object
X
#weatherModule h3{color:red;}
#tabs h3{color:blue}




 DEFINE DEFAULT VALUES
       Don’t repeat this code in every object
X
#weatherModule h3{color:red;}
#tabs h3{color:blue}




 DEFINE DEFAULT VALUES
       Don’t repeat this code in every object
               h1,    .h1{...}
               h2,    .h2{...}
               h3,    .h3{...}
               h4,    .h4{...}
               h5,    .h5{...}
               h6,    .h6{...}
DEFINE STRUCTURE IN A
   SEPARATE CLASS
   Don’t repeat this code in every object
                                       block
                                          inner
                                                  hd




                                                  bd




                                                  ft
div.error{...}




           STYLE CLASSES
                 rather than elements
X
div.error{...}




           STYLE CLASSES
                 rather than elements


 .error{           most of the code goes here   }
X
  div.error{...}




             STYLE CLASSES
                   rather than elements


   .error{           most of the code goes here   }
div.error{                                        }
  p.error{                  exceptions only       }
 em.error{                                        }
div{...}
 ul{...}
 p{..}




AVOID STYLING ELEMENTS
            unless defining defaults
div{...}
  X
 ul{...}
 p{..}




AVOID STYLING ELEMENTS
            unless defining defaults
               .error{...}
              .section{...}
             .products{...}
.myModule .inner b{...}
.myModule2 b {...}


          GIVE RULES THE
         SAME STRENGTH
      Use cascade order to overwrite previous rules
X
.myModule .inner b{...}
.myModule2 b {...}


          GIVE RULES THE
         SAME STRENGTH
      Use cascade order to overwrite previous rules



     .myModule b{...}
     .myModule2 b {...}
.sidebar ul{...}
.header ul {...}


      AVOID SPECIFYING
         LOCATION
      Apply classes to the object you wish to change
X
.sidebar ul{...}
.header ul {...}


      AVOID SPECIFYING
         LOCATION
      Apply classes to the object you wish to change



     .mainNav{...}
     .subNav {...}
AVOID OVERLY SPECIFIC
      CLASSES
    they’re all semantic, but limiting
AVOID OVERLY SPECIFIC
      CLASSES
     they’re all semantic, but limiting

 .vehicle{...}
 .motorcycle{...}
 .ducati{...}
 .ducatiMonster620{...}
 .nicolesDucatiMonster620{...}
AVOID OVERLY SPECIFIC
      CLASSES
     they’re all semantic, but limiting

 .vehicle{...}
 .motorcycle{...}
 .ducati{...}

   X
 .ducatiMonster620{...}
 .nicolesDucatiMonster620{...}
#myUniqueIdentifier{...}
   #myUniqueIdentifier2{...}




                       AVOID SINGLETONS
                       ids can only be used once in any given page




Source: Chris Griego
X
   #myUniqueIdentifier{...}
   #myUniqueIdentifier2{...}




                       AVOID SINGLETONS
                       ids can only be used once in any given page




Source: Chris Griego
Media
                 Subheading
                 Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
                 aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
                 aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
                 cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.




                          USE MIXINS
                                 to avoid repeating code


Media Extended
Subheading
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
.inner{...}        .weatherMod .inner{...}
.tr{...}           .weatherMod .tr{...}
.bl{...}           .weatherMod .bl{...}



      ENCAPSULATION
     don’t access sub-nodes of an object directly



                          inner
.inner{...}
  X
                   .weatherMod .inner{...}
.tr{...}           .weatherMod .tr{...}
.bl{...}           .weatherMod .bl{...}



      ENCAPSULATION
     don’t access sub-nodes of an object directly



                          inner

More Related Content

KEY
The Fast And The Fabulous
KEY
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
PDF
CSS - OOCSS, SMACSS and more
PDF
Css3 and gwt in perfect harmony
PPTX
Scalable and Modular CSS FTW!
PDF
CSS3 - is everything we used to do wrong?
PPT
CSS Methodology
PPT
Html & Css presentation
The Fast And The Fabulous
The Cascade, Grids, Headings, and Selectors from an OOCSS Perspective, Ajax ...
CSS - OOCSS, SMACSS and more
Css3 and gwt in perfect harmony
Scalable and Modular CSS FTW!
CSS3 - is everything we used to do wrong?
CSS Methodology
Html & Css presentation

What's hot (20)

PDF
What's Object-Oriented CSS (japanese)
PDF
SMACSS Workshop
PDF
Introduction to CSS3
PDF
Css3 and gwt in perfect harmony
PDF
OOCSS, SMACSS or BEM?
PDF
CSS 開發加速指南-Sass & Compass
PDF
CSS3 meets GWT with GSS
PPTX
PDF
Efficient, maintainable CSS
PDF
Introduction to CSS3
PDF
CSS: a rapidly changing world
PDF
The Near Future of CSS
ODP
Introduction To Less
PDF
BEM it!
PPTX
New Elements & Features in CSS3
PPTX
SASS is more than LESS
PPTX
PDF
CSS Reset
PPTX
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
What's Object-Oriented CSS (japanese)
SMACSS Workshop
Introduction to CSS3
Css3 and gwt in perfect harmony
OOCSS, SMACSS or BEM?
CSS 開發加速指南-Sass & Compass
CSS3 meets GWT with GSS
Efficient, maintainable CSS
Introduction to CSS3
CSS: a rapidly changing world
The Near Future of CSS
Introduction To Less
BEM it!
New Elements & Features in CSS3
SASS is more than LESS
CSS Reset
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
Ad

Similar to Taming CSS Selectors (20)

PDF
Advanced Debugging in XCode
PDF
(Greach 2015) Dsl'ing your Groovy
KEY
What is Object Oriented CSS?
PDF
Clean code
PDF
Rapid web development, the right way.
KEY
CSS Wish List @JSConf
PDF
Bronx study jam 1
PDF
Clean code in JavaScript
PDF
Test-driven Development (TDD)
DOCX
#include -iostream- #include -vector- #include -Date-h- #include -Pers.docx
DOCX
#include -iostream- #include -vector- #include -Date-h- #include -Pers.docx
PDF
Web Components Everywhere
PDF
Supercharge Flutter declarative UI with code generation
KEY
Sass Essentials at Mobile Camp LA
PDF
Professional Code Reviews - Bogdan Gusiev
PDF
Type level programming in Scala
ODP
New Ideas for Old Code - Greach
PPTX
Clean Code
PDF
Lift off with Groovy 2 at JavaOne 2013
PDF
Clean code
Advanced Debugging in XCode
(Greach 2015) Dsl'ing your Groovy
What is Object Oriented CSS?
Clean code
Rapid web development, the right way.
CSS Wish List @JSConf
Bronx study jam 1
Clean code in JavaScript
Test-driven Development (TDD)
#include -iostream- #include -vector- #include -Date-h- #include -Pers.docx
#include -iostream- #include -vector- #include -Date-h- #include -Pers.docx
Web Components Everywhere
Supercharge Flutter declarative UI with code generation
Sass Essentials at Mobile Camp LA
Professional Code Reviews - Bogdan Gusiev
Type level programming in Scala
New Ideas for Old Code - Greach
Clean Code
Lift off with Groovy 2 at JavaOne 2013
Clean code
Ad

More from Nicole Sullivan (13)

PDF
Building the Media Block in ReactJS
PDF
Why are you here?
PDF
Creating Living Style Guides to Improve Performance
PDF
Don't feed the trolls
PDF
CSS Power Tools
PDF
Our Best Practices Are Killing Us
PDF
CSS Bloat!
PDF
5 Mistakes of Massive CSS
KEY
Object Oriented CSS
PDF
Pourquoi la performance?
PDF
Design Fast Websites
PDF
7 Habits of Exceptional Performance
PPT
After YSlow "A"
Building the Media Block in ReactJS
Why are you here?
Creating Living Style Guides to Improve Performance
Don't feed the trolls
CSS Power Tools
Our Best Practices Are Killing Us
CSS Bloat!
5 Mistakes of Massive CSS
Object Oriented CSS
Pourquoi la performance?
Design Fast Websites
7 Habits of Exceptional Performance
After YSlow "A"

Recently uploaded (20)

PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Newfamily of error-correcting codes based on genetic algorithms
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Advanced IT Governance
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
CroxyProxy Instagram Access id login.pptx
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 2 Digital Image Fundamentals.pdf
Transforming Manufacturing operations through Intelligent Integrations
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Electronic commerce courselecture one. Pdf
Newfamily of error-correcting codes based on genetic algorithms
NewMind AI Weekly Chronicles - August'25 Week I
SAP855240_ALP - Defining the Global Template PUBLIC.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
GamePlan Trading System Review: Professional Trader's Honest Take
Advanced IT Governance
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Advanced Soft Computing BINUS July 2025.pdf
CroxyProxy Instagram Access id login.pptx
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
CIFDAQ's Market Insight: SEC Turns Pro Crypto

Taming CSS Selectors

  • 1. TAMING SELECTORS sanity for our stylesheets
  • 2. SIZE OF THE CSS FILE AND IMPLIED HTTP REQUESTS are the biggest factor for CSS performance
  • 3. REFLOWS AND RENDERING TIME are (much!) less important
  • 4. DUPLICATION IS WORSE THAN STALE RULES because we have tools to deal with the later
  • 5. DEFINE DEFAULT VALUES Don’t repeat this code in every object
  • 6. #weatherModule h3{color:red;} #tabs h3{color:blue} DEFINE DEFAULT VALUES Don’t repeat this code in every object
  • 7. X #weatherModule h3{color:red;} #tabs h3{color:blue} DEFINE DEFAULT VALUES Don’t repeat this code in every object
  • 8. X #weatherModule h3{color:red;} #tabs h3{color:blue} DEFINE DEFAULT VALUES Don’t repeat this code in every object h1, .h1{...} h2, .h2{...} h3, .h3{...} h4, .h4{...} h5, .h5{...} h6, .h6{...}
  • 9. DEFINE STRUCTURE IN A SEPARATE CLASS Don’t repeat this code in every object block inner hd bd ft
  • 10. div.error{...} STYLE CLASSES rather than elements
  • 11. X div.error{...} STYLE CLASSES rather than elements .error{ most of the code goes here }
  • 12. X div.error{...} STYLE CLASSES rather than elements .error{ most of the code goes here } div.error{ } p.error{ exceptions only } em.error{ }
  • 13. div{...} ul{...} p{..} AVOID STYLING ELEMENTS unless defining defaults
  • 14. div{...} X ul{...} p{..} AVOID STYLING ELEMENTS unless defining defaults .error{...} .section{...} .products{...}
  • 15. .myModule .inner b{...} .myModule2 b {...} GIVE RULES THE SAME STRENGTH Use cascade order to overwrite previous rules
  • 16. X .myModule .inner b{...} .myModule2 b {...} GIVE RULES THE SAME STRENGTH Use cascade order to overwrite previous rules .myModule b{...} .myModule2 b {...}
  • 17. .sidebar ul{...} .header ul {...} AVOID SPECIFYING LOCATION Apply classes to the object you wish to change
  • 18. X .sidebar ul{...} .header ul {...} AVOID SPECIFYING LOCATION Apply classes to the object you wish to change .mainNav{...} .subNav {...}
  • 19. AVOID OVERLY SPECIFIC CLASSES they’re all semantic, but limiting
  • 20. AVOID OVERLY SPECIFIC CLASSES they’re all semantic, but limiting .vehicle{...} .motorcycle{...} .ducati{...} .ducatiMonster620{...} .nicolesDucatiMonster620{...}
  • 21. AVOID OVERLY SPECIFIC CLASSES they’re all semantic, but limiting .vehicle{...} .motorcycle{...} .ducati{...} X .ducatiMonster620{...} .nicolesDucatiMonster620{...}
  • 22. #myUniqueIdentifier{...} #myUniqueIdentifier2{...} AVOID SINGLETONS ids can only be used once in any given page Source: Chris Griego
  • 23. X #myUniqueIdentifier{...} #myUniqueIdentifier2{...} AVOID SINGLETONS ids can only be used once in any given page Source: Chris Griego
  • 24. Media Subheading Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. USE MIXINS to avoid repeating code Media Extended Subheading Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  • 25. .inner{...} .weatherMod .inner{...} .tr{...} .weatherMod .tr{...} .bl{...} .weatherMod .bl{...} ENCAPSULATION don’t access sub-nodes of an object directly inner
  • 26. .inner{...} X .weatherMod .inner{...} .tr{...} .weatherMod .tr{...} .bl{...} .weatherMod .bl{...} ENCAPSULATION don’t access sub-nodes of an object directly inner