SlideShare a Scribd company logo
CSS
BEST PRACTICE
Best practice
“Best practice” is a very loose
and often poorly defined term.
“Best practice” often comes down
      to personal opinion.
“Best practice” can depend on the
   team environment you are
            working in.
“Best practice” may also depend
on the applications you have to
            work with.
Your personal “best practices”
may change radically over time!
With that in mind, here are some
 tips that may help you when
setting up CSS files in the future.
Applying CSS
1. Avoid using inline styles as
    they are hard to maintain and
          increase file size.

                           Avoid
<body>
<h2 style=“color: red;”>
!   Heading here
</h2>
2. Avoid using header styles as
     they are also hard to maintain
         and increase file size.


                      Avoid
<style>
  p { color: red; }
</style>
3. Avoid using @import within the
   HTML as this will slow down IE
              browsers.

                     Avoid
<style>
  @import "a.css";
</style>
4. Avoid using multiple CSS
    files, or combine all CSS files
        before final production.

                               Avoid

<link   rel="stylesheet"   href="reset.css">
<link   rel="stylesheet"   href="grids.css">
<link   rel="stylesheet"   href="text.css">
<link   rel="stylesheet"   href="modules.css">
<link   rel="stylesheet"   href="colors.css">
Writing CSS rules
5. Use multiple declarations
           where possible



p
{
!   margin: 0 0 1.5em;
!   background: green;
}
6. Use multiple selectors
           where possible



h1, h2, h3, h4, h5
{
!   color: #666;
!   margin: 0 0 .5em;
}
7. Use shorthand properties
           where possible

body
{                             Avoid
  margin-top: 20px;
  margin-right: 10px;
  margin-bottom: 20px;
  margin-left: 10px;
}                             Preferred

body { margin: 20px 10px; }
8. Avoid !important as it is often
     unnecessary - especially when
      you understand the cascade.


p                           Avoid
{
!   margin: 0 !important;
}
9. Avoid complex selectors
    (taxing for browsers). Try to be
      only as specific as needed.

                        Avoid

#navigation ul li a { margin: 0; }

#navigation a { margin: 0; }

                 Preferred
10. Avoid universal selectors.



          Avoid

.nav * { margin: 0; }
11. Avoid qualifying selectors as
       this is often unnecessary.


              Avoid

div.nav { }

.nav { }

           Preferred
12. Avoid IE-proprietary filters
  as they slow page performance.


            Avoid

filter:Alpha(Opacity=40);
-ms-filter: "Alpha(Opacity=40)";
13. Avoid IDs. Where possible
         use classes instead.


            Avoid

#header { ... }

.header { ... }

         Preferred
14. Try not to use too many
       font-size declarations.



h1 { font-size: 200%; }
                               Avoid
.nav { font-size: 80%; }
.widget { font-size: 70%; }
.intro { font-size: 110%; }
.sidebar { font-size: 85%; }
Optimisation
15. Some people like to use a
 CSS minifier to reduce your
    overall CSS file size:
     http://refresh-sf.com/yui/
16. Optimise images as much as
           possible
17. Where possible, combine
    images into sprites.
18. If possible, use CSS3 rules
     instead of images to reduce
    server requests and page size.

            Avoid

p { background: url(round-corners.png); }

p { border-radius: 10px; }

         Preferred
Russ Weakley
Max Design

Site: maxdesign.com.au
Twitter: twitter.com/russmaxdesign
Slideshare: slideshare.net/maxdesign
Linkedin: linkedin.com/in/russweakley

More Related Content

What's hot (20)

PPTX
Beginners css tutorial for web designers
Singsys Pte Ltd
 
PPTX
1 03 - CSS Introduction
apnwebdev
 
PPTX
SASS - CSS with Superpower
Kanchha kaji Prajapati
 
PPTX
Complete Lecture on Css presentation
Salman Memon
 
PPT
Css Ppt
Hema Prasanth
 
PPT
Introduction to BOOTSTRAP
Jeanie Arnoco
 
PPTX
Media queries A to Z
Shameem Reza
 
PPT
Span and Div tags in HTML
Biswadip Goswami
 
PDF
HTML CSS Basics
Mai Moustafa
 
PPTX
html-css
Dhirendra Chauhan
 
PPT
Cascading Style Sheets (CSS) help
casestudyhelp
 
PDF
HTML5: features with examples
Alfredo Torre
 
PPTX
Html n CSS
Sukrit Gupta
 
PPTX
Introduction to SASS
Jon Dean
 
PDF
HTML & CSS Masterclass
Bernardo Raposo
 
PDF
CSS Day: CSS Grid Layout
Rachel Andrew
 
PDF
Basic-CSS-tutorial
tutorialsruby
 
PPTX
HTML/HTML5
People Strategists
 
PPTX
Basic of HTML, CSS(StyleSheet), JavaScript(js), Bootstrap, JSON & AngularJS
Deepak Upadhyay
 
Beginners css tutorial for web designers
Singsys Pte Ltd
 
1 03 - CSS Introduction
apnwebdev
 
SASS - CSS with Superpower
Kanchha kaji Prajapati
 
Complete Lecture on Css presentation
Salman Memon
 
Css Ppt
Hema Prasanth
 
Introduction to BOOTSTRAP
Jeanie Arnoco
 
Media queries A to Z
Shameem Reza
 
Span and Div tags in HTML
Biswadip Goswami
 
HTML CSS Basics
Mai Moustafa
 
Cascading Style Sheets (CSS) help
casestudyhelp
 
HTML5: features with examples
Alfredo Torre
 
Html n CSS
Sukrit Gupta
 
Introduction to SASS
Jon Dean
 
HTML & CSS Masterclass
Bernardo Raposo
 
CSS Day: CSS Grid Layout
Rachel Andrew
 
Basic-CSS-tutorial
tutorialsruby
 
HTML/HTML5
People Strategists
 
Basic of HTML, CSS(StyleSheet), JavaScript(js), Bootstrap, JSON & AngularJS
Deepak Upadhyay
 

Viewers also liked (10)

PDF
AngularJS best-practices
Henry Tao
 
PDF
AngularJS Best Practices
Betclic Everest Group Tech Team
 
PPTX
Mobile Email Design, Strategies, Workflow and Best Practices
Litmus
 
PDF
New Features in Angular 1.5
Kenichi Kanai
 
PDF
The Art of AngularJS in 2015
Matt Raible
 
PPTX
AngularJS best practices
Filip Bruun Bech-Larsen
 
PPTX
Media queries and frameworks
Nicole Ryan
 
PDF
Beyond Media Queries: Anatomy of an Adaptive Web Design
Brad Frost
 
PPT
Css best practices style guide and tips
Chris Love
 
PPTX
AngularJS Best Practices
Narek Mamikonyan
 
AngularJS best-practices
Henry Tao
 
AngularJS Best Practices
Betclic Everest Group Tech Team
 
Mobile Email Design, Strategies, Workflow and Best Practices
Litmus
 
New Features in Angular 1.5
Kenichi Kanai
 
The Art of AngularJS in 2015
Matt Raible
 
AngularJS best practices
Filip Bruun Bech-Larsen
 
Media queries and frameworks
Nicole Ryan
 
Beyond Media Queries: Anatomy of an Adaptive Web Design
Brad Frost
 
Css best practices style guide and tips
Chris Love
 
AngularJS Best Practices
Narek Mamikonyan
 
Ad

Similar to CSS Best practice (20)

PDF
Efficient, maintainable CSS
Russ Weakley
 
PDF
Advanced CSS Troubleshooting
Denise Jacobs
 
PDF
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
PPT
Css Best Practices
sachin9737
 
PPT
Css Best Practices
guest3ebcca
 
PDF
Highly Maintainable, Efficient, and Optimized CSS
Zoe Gillenwater
 
PDF
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
DOCX
INTEGRATION (HTML/CSS) The technology behind AESTHETICS
Siddharth Lale
 
PPT
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
PPTX
Html Css Mistakes
Tasawr Interactive
 
PDF
CSS Systems
Natalie Downe
 
KEY
HTML CSS & Javascript
David Lindkvist
 
PPTX
Sayed-Minhal-Best Practice
Sayed Minhal
 
PPTX
Sayed minhal-best practice
Sayed Minhal
 
PDF
Improving Web Usability in the Search for a Cure
Douglas Yuen
 
PPT
Performance optimization - Basics
Filip Mares
 
PDF
Pediatric Therapy Center Re-Branding & Style Guide
Carla Crandall
 
PPTX
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
Bastian Grimm
 
ODP
Design Best Practices for WordPress
Suzette Franck
 
KEY
Object Oriented CSS
Nicole Sullivan
 
Efficient, maintainable CSS
Russ Weakley
 
Advanced CSS Troubleshooting
Denise Jacobs
 
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
Css Best Practices
sachin9737
 
Css Best Practices
guest3ebcca
 
Highly Maintainable, Efficient, and Optimized CSS
Zoe Gillenwater
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
INTEGRATION (HTML/CSS) The technology behind AESTHETICS
Siddharth Lale
 
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
Html Css Mistakes
Tasawr Interactive
 
CSS Systems
Natalie Downe
 
HTML CSS & Javascript
David Lindkvist
 
Sayed-Minhal-Best Practice
Sayed Minhal
 
Sayed minhal-best practice
Sayed Minhal
 
Improving Web Usability in the Search for a Cure
Douglas Yuen
 
Performance optimization - Basics
Filip Mares
 
Pediatric Therapy Center Re-Branding & Style Guide
Carla Crandall
 
10 Tips to make your Website lightning-fast - SMX Stockholm 2012
Bastian Grimm
 
Design Best Practices for WordPress
Suzette Franck
 
Object Oriented CSS
Nicole Sullivan
 
Ad

More from Russ Weakley (20)

PDF
Accessible chat windows
Russ Weakley
 
PDF
Accessible names & descriptions
Russ Weakley
 
PDF
A deep dive into accessible names
Russ Weakley
 
PDF
What are accessible names and why should you care?
Russ Weakley
 
PDF
How to build accessible UI components
Russ Weakley
 
PDF
What is WCAG 2 and why should we care?
Russ Weakley
 
PDF
Accessible states in Design Systems
Russ Weakley
 
PDF
Creating accessible modals and autocompletes
Russ Weakley
 
PDF
Building an accessible progressive loader
Russ Weakley
 
PDF
Accessibility in Design systems - the pain and glory
Russ Weakley
 
PDF
Accessible Inline errors messages
Russ Weakley
 
PDF
Accessible Form Hints and Errors
Russ Weakley
 
PDF
What is accessibility?
Russ Weakley
 
PDF
Accessibility in Pattern Libraries
Russ Weakley
 
PDF
Accessibility in pattern libraries
Russ Weakley
 
PDF
Building an accessible auto-complete - #ID24
Russ Weakley
 
PDF
Building an accessible auto-complete
Russ Weakley
 
PDF
Creating Acessible floating labels
Russ Weakley
 
PDF
Creating an Accessible button dropdown
Russ Weakley
 
PDF
Creating a Simple, Accessible On/Off Switch
Russ Weakley
 
Accessible chat windows
Russ Weakley
 
Accessible names & descriptions
Russ Weakley
 
A deep dive into accessible names
Russ Weakley
 
What are accessible names and why should you care?
Russ Weakley
 
How to build accessible UI components
Russ Weakley
 
What is WCAG 2 and why should we care?
Russ Weakley
 
Accessible states in Design Systems
Russ Weakley
 
Creating accessible modals and autocompletes
Russ Weakley
 
Building an accessible progressive loader
Russ Weakley
 
Accessibility in Design systems - the pain and glory
Russ Weakley
 
Accessible Inline errors messages
Russ Weakley
 
Accessible Form Hints and Errors
Russ Weakley
 
What is accessibility?
Russ Weakley
 
Accessibility in Pattern Libraries
Russ Weakley
 
Accessibility in pattern libraries
Russ Weakley
 
Building an accessible auto-complete - #ID24
Russ Weakley
 
Building an accessible auto-complete
Russ Weakley
 
Creating Acessible floating labels
Russ Weakley
 
Creating an Accessible button dropdown
Russ Weakley
 
Creating a Simple, Accessible On/Off Switch
Russ Weakley
 

Recently uploaded (20)

PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Dimensions of Societal Planning in Commonism
StefanMz
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 

CSS Best practice

  • 3. “Best practice” is a very loose and often poorly defined term.
  • 4. “Best practice” often comes down to personal opinion.
  • 5. “Best practice” can depend on the team environment you are working in.
  • 6. “Best practice” may also depend on the applications you have to work with.
  • 7. Your personal “best practices” may change radically over time!
  • 8. With that in mind, here are some tips that may help you when setting up CSS files in the future.
  • 10. 1. Avoid using inline styles as they are hard to maintain and increase file size. Avoid <body> <h2 style=“color: red;”> ! Heading here </h2>
  • 11. 2. Avoid using header styles as they are also hard to maintain and increase file size. Avoid <style> p { color: red; } </style>
  • 12. 3. Avoid using @import within the HTML as this will slow down IE browsers. Avoid <style> @import "a.css"; </style>
  • 13. 4. Avoid using multiple CSS files, or combine all CSS files before final production. Avoid <link rel="stylesheet" href="reset.css"> <link rel="stylesheet" href="grids.css"> <link rel="stylesheet" href="text.css"> <link rel="stylesheet" href="modules.css"> <link rel="stylesheet" href="colors.css">
  • 15. 5. Use multiple declarations where possible p { ! margin: 0 0 1.5em; ! background: green; }
  • 16. 6. Use multiple selectors where possible h1, h2, h3, h4, h5 { ! color: #666; ! margin: 0 0 .5em; }
  • 17. 7. Use shorthand properties where possible body { Avoid margin-top: 20px; margin-right: 10px; margin-bottom: 20px; margin-left: 10px; } Preferred body { margin: 20px 10px; }
  • 18. 8. Avoid !important as it is often unnecessary - especially when you understand the cascade. p Avoid { ! margin: 0 !important; }
  • 19. 9. Avoid complex selectors (taxing for browsers). Try to be only as specific as needed. Avoid #navigation ul li a { margin: 0; } #navigation a { margin: 0; } Preferred
  • 20. 10. Avoid universal selectors. Avoid .nav * { margin: 0; }
  • 21. 11. Avoid qualifying selectors as this is often unnecessary. Avoid div.nav { } .nav { } Preferred
  • 22. 12. Avoid IE-proprietary filters as they slow page performance. Avoid filter:Alpha(Opacity=40); -ms-filter: "Alpha(Opacity=40)";
  • 23. 13. Avoid IDs. Where possible use classes instead. Avoid #header { ... } .header { ... } Preferred
  • 24. 14. Try not to use too many font-size declarations. h1 { font-size: 200%; } Avoid .nav { font-size: 80%; } .widget { font-size: 70%; } .intro { font-size: 110%; } .sidebar { font-size: 85%; }
  • 26. 15. Some people like to use a CSS minifier to reduce your overall CSS file size: http://refresh-sf.com/yui/
  • 27. 16. Optimise images as much as possible
  • 28. 17. Where possible, combine images into sprites.
  • 29. 18. If possible, use CSS3 rules instead of images to reduce server requests and page size. Avoid p { background: url(round-corners.png); } p { border-radius: 10px; } Preferred
  • 30. Russ Weakley Max Design Site: maxdesign.com.au Twitter: twitter.com/russmaxdesign Slideshare: slideshare.net/maxdesign Linkedin: linkedin.com/in/russweakley