SlideShare a Scribd company logo
CSS BEST PRACTICES By Sachin Chaudhari – Zensar Technologies
Introduction This Presentation is consolidation of the CSS (Cascading Style Sheet) best practices during web development.
Advantages of CSS CSS helps to reduce html code Pages load faster Easy for maintenance  Saves time
Types of CSS Inline styles Inline styles are styles that are written directly in the tag on the document. Inline styles affect only the tag they are applied to. <a href=&quot;&quot; style=&quot;text-decoration: none;&quot;> Embedded/Internal styles Embedded or Internal styles are styles that are embedded in the head of the document. Embedded styles affect only the tags on the page they are embedded in. <style type=&quot;text/css“> p { color: #00f; } </style> External styles External styles are styles that are written in a separate document and then attached to various documents. External style sheets can affect any document they are attached to. <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot; />
CSS Best Practices Use a Reset Resets essentially eliminate browser inconsistencies such as heights, font sizes, margins, headings, etc. The reset allows your layout look consistent in all browsers.  Example: body, h1,h2,h3,h4,h5,h6,form,fieldset,input,textarea,p {  margin:0; padding:0; } table { border-collapse:collapse; border-spacing:0; } fieldset,img {  border:0; } ol,ul { list-style:none; }
CSS Best Practices Organize the Stylesheet with a logical Structure lay your stylesheet out in a way that allows you to quickly find parts of your code.  So, an example stylesheet might be ordered like this: Generic classes (body, a, p, h1, etc.) /****** header *********/ styles goes here... /****** header End*********/ /****** main content *********/ styles goes here... /****** main content End*********/ /****** footer *********/ styles go here... /****** footer End *********/ /****** common*********/ styles go here... /****** common End *********/
CSS Best Practices Make it Readable The readability of your CSS is incredibly important, though most people overlook why it's important. Great readability of your CSS makes it much easier to maintain in the future, as you'll be able to find elements quicker.  Also, you'll never know who might need to look at your code later on.  All on one line .content { background: red; padding: 2em; border: 1px solid black; } on different line .content {  background: red;  padding: 2em;  border: 1px solid black;  }
CSS Best Practices Keep it Consistent Along the lines of keeping your code readable is making sure that the CSS is consistent.  develop your own &quot;sub-language&quot; of CSS that allows you to quickly name things.  There are certain classes that I create in nearly every application, and I use the same name each time. For example, I use &quot;.dbfl&quot; to float divs to the left. Good Example .dbfl { display:block;  float:left; } .dbfr { display:block;  float:right; } Bad Example .dbfl { display:block;  float:left; } .dbfr { float:right; display:block; }
CSS Best Practices Combine Elements Elements in a stylesheet sometimes share properties.  Instead of re-writing the same properties just combine them. For example, your h1, h2, and h3 elements might all share the same font and color: h1, h2, h3 {font-family: tahoma, color: #333}
CSS Best Practices Use Multiple Classes Sometimes it's beneficial to add multiple classes to an element.  Let's say that you have a <div> having class &quot;box&quot; which defines color and font properties .  <div class=&quot;box&quot;></div> Now you want to float it right, and you've already got a class . right  in your CSS that floats everything to the right. You can simply add an extra class in the declaration, like so: <div class=&quot;box right&quot;></div>
CSS Best Practices Use Shorthand while declarations Comment your CSS  Avoid Using Inline Styles
CSS Best Practices Validate your CSS Validating your CSS does more than give a sense of pride:  it helps you quickly spot errors in your code. Validation Service http://jigsaw.w3.org/css-validator/
THANK YOU

More Related Content

What's hot (15)

ODP
Introduction to css & its attributes with syntax
priyadharshini murugan
 
PPSX
Introduction to css
Evolution Network
 
PPTX
Css introduction
AbhishekMondal42
 
PPTX
Week 12 CSS - Review from last week
Katherine McCurdy-Lapierre, R.G.D.
 
PPTX
Cascading Style Sheets (CSS)
Harshil Darji
 
KEY
Web Design, Lesson Plan: Classes and IDs
Steve Kinney
 
PDF
Html css
kanakaiah kedam
 
PPT
Html Expression Web
Mark Frydenberg
 
PPT
INFO3775 Chapter 2 Part 2
Jeff Byrnes
 
PPT
Week3 css
Rowena LI
 
PPTX
CSS introduction
CloudTech 
 
PPT
CSS Introduction
Swati Sharma
 
Introduction to css & its attributes with syntax
priyadharshini murugan
 
Introduction to css
Evolution Network
 
Css introduction
AbhishekMondal42
 
Week 12 CSS - Review from last week
Katherine McCurdy-Lapierre, R.G.D.
 
Cascading Style Sheets (CSS)
Harshil Darji
 
Web Design, Lesson Plan: Classes and IDs
Steve Kinney
 
Html css
kanakaiah kedam
 
Html Expression Web
Mark Frydenberg
 
INFO3775 Chapter 2 Part 2
Jeff Byrnes
 
Week3 css
Rowena LI
 
CSS introduction
CloudTech 
 
CSS Introduction
Swati Sharma
 

Viewers also liked (8)

PDF
04 kulakov jet style
Natalia Korotonoshkina
 
DOC
Eng Abdullah Allam Cv
abdo366
 
PPTX
Webtop
nish_d1
 
PDF
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
Orange Dev
 
PDF
2013 2014 ieee btech mtech dotnet projects richbraintechnologies
IEEEBTECHMTECHPROJECTS
 
DOCX
Words
C Russo
 
PDF
Flexible DataSync: Fuel for new business opportunities
Orange Dev
 
PPS
Meeting Point Webtop
Jeff Mowatt
 
04 kulakov jet style
Natalia Korotonoshkina
 
Eng Abdullah Allam Cv
abdo366
 
Webtop
nish_d1
 
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
Orange Dev
 
2013 2014 ieee btech mtech dotnet projects richbraintechnologies
IEEEBTECHMTECHPROJECTS
 
Words
C Russo
 
Flexible DataSync: Fuel for new business opportunities
Orange Dev
 
Meeting Point Webtop
Jeff Mowatt
 
Ad

Similar to Css Best Practices (20)

PDF
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
PPT
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
PDF
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
PDF
Advanced CSS Troubleshooting
Denise Jacobs
 
PPT
CSS Basics
WordPress Memphis
 
PDF
Maintainable CSS
Stephen Hay
 
PDF
6 Steps to Make Your CSS Code More Maintainable
10Clouds
 
PPT
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
PPT
CSS Best practices
José Teixidó
 
PPT
Modern front end development
Tricode (part of Dept)
 
PDF
CSS Best practice
Russ Weakley
 
PPT
Css
NIRMAL FELIX
 
ODP
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
PPT
Make Css easy(part:2) : easy tips for css(part:2)
shabab shihan
 
PPT
Basics Of Css And Some Common Mistakes
sanjay2211
 
PDF
Efficient, maintainable CSS
Russ Weakley
 
PDF
Introduction to Frontend Development - Session 2 - CSS Fundamentals
Kalin Chernev
 
PPT
CSS Methodology
Zohar Arad
 
Structuring your CSS for maintainability: rules and guile lines to write CSS
Sanjoy Kr. Paul
 
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
Advanced CSS Troubleshooting
Denise Jacobs
 
CSS Basics
WordPress Memphis
 
Maintainable CSS
Stephen Hay
 
6 Steps to Make Your CSS Code More Maintainable
10Clouds
 
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
CSS Best practices
José Teixidó
 
Modern front end development
Tricode (part of Dept)
 
CSS Best practice
Russ Weakley
 
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
Make Css easy(part:2) : easy tips for css(part:2)
shabab shihan
 
Basics Of Css And Some Common Mistakes
sanjay2211
 
Efficient, maintainable CSS
Russ Weakley
 
Introduction to Frontend Development - Session 2 - CSS Fundamentals
Kalin Chernev
 
CSS Methodology
Zohar Arad
 
Ad

Recently uploaded (20)

PDF
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
PPTX
Bldg Mtc 8 Maintance documentation and audits - 25 (2).pptx
MwanamomoMpamba
 
PDF
Presentation of design made by power point
habibikuw002
 
PPTX
Adjective..pptxujjjjjjjjjjjjjjjjjjjjjjjj
seemanodiyal
 
PDF
WEEK3-Literary-Gennnnnnnnnnnnnnnnnres.pdf
MaybelynVergara
 
PPTX
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
PPTX
Transportation in the air, sea and land.pptx
KhloodAli5
 
PPTX
High-Rise Interior Mastery by Top 3D Visualization Experts
Yantram Animation Studio Corporation
 
PDF
Uber Driver Hackday Sprint Solving Ride Cancellations
YellowSlice1
 
PDF
🔴BUKTI KEMENANGAN HARI INI SELASA 08 JULI 2025 !!!🔴
GRAB
 
PDF
Presentation - Interior Design Concepts (2).pdf
vrindagrawal456
 
PDF
SS27 Men's Fashion Trend Book Peclers Paris
Peclers Paris
 
PDF
Case Study on good and bad acoustics in auditorium
Disha Agrawal
 
PDF
S2 Associates brings museum exhibits to life with innovative design.pdf
S2 Associates
 
PDF
The Role of Logos as Identity Shapers (IFIC Logo)
Md. Mehedi Hasan Asif
 
PPTX
Visit Biogas Refresher Slide_Jun 2025.pptx
isyraffemir
 
PDF
Black and Blue Modern Technology Presentation.pdf
hjaders1104
 
PPTX
Town planning is a concept used in architectural design. It plays a very impo...
IshikaPanchal11
 
PPTX
Chapter 2-3.pptxnsnsnsnsnsjsjsjsjejeusuejsjsj
hibaaqabdirisaaq331
 
PPTX
condylar pptx.in relation to dental seurgery
abishekgowtham586
 
CRAC- Adobe Photoshop CC 2016 (32 64Bit) Crack
utfefguu
 
Bldg Mtc 8 Maintance documentation and audits - 25 (2).pptx
MwanamomoMpamba
 
Presentation of design made by power point
habibikuw002
 
Adjective..pptxujjjjjjjjjjjjjjjjjjjjjjjj
seemanodiyal
 
WEEK3-Literary-Gennnnnnnnnnnnnnnnnres.pdf
MaybelynVergara
 
(2) Cell Wall Inhibitors_Cephalosporins others.pptx
mkurdi133
 
Transportation in the air, sea and land.pptx
KhloodAli5
 
High-Rise Interior Mastery by Top 3D Visualization Experts
Yantram Animation Studio Corporation
 
Uber Driver Hackday Sprint Solving Ride Cancellations
YellowSlice1
 
🔴BUKTI KEMENANGAN HARI INI SELASA 08 JULI 2025 !!!🔴
GRAB
 
Presentation - Interior Design Concepts (2).pdf
vrindagrawal456
 
SS27 Men's Fashion Trend Book Peclers Paris
Peclers Paris
 
Case Study on good and bad acoustics in auditorium
Disha Agrawal
 
S2 Associates brings museum exhibits to life with innovative design.pdf
S2 Associates
 
The Role of Logos as Identity Shapers (IFIC Logo)
Md. Mehedi Hasan Asif
 
Visit Biogas Refresher Slide_Jun 2025.pptx
isyraffemir
 
Black and Blue Modern Technology Presentation.pdf
hjaders1104
 
Town planning is a concept used in architectural design. It plays a very impo...
IshikaPanchal11
 
Chapter 2-3.pptxnsnsnsnsnsjsjsjsjejeusuejsjsj
hibaaqabdirisaaq331
 
condylar pptx.in relation to dental seurgery
abishekgowtham586
 

Css Best Practices

  • 1. CSS BEST PRACTICES By Sachin Chaudhari – Zensar Technologies
  • 2. Introduction This Presentation is consolidation of the CSS (Cascading Style Sheet) best practices during web development.
  • 3. Advantages of CSS CSS helps to reduce html code Pages load faster Easy for maintenance Saves time
  • 4. Types of CSS Inline styles Inline styles are styles that are written directly in the tag on the document. Inline styles affect only the tag they are applied to. <a href=&quot;&quot; style=&quot;text-decoration: none;&quot;> Embedded/Internal styles Embedded or Internal styles are styles that are embedded in the head of the document. Embedded styles affect only the tags on the page they are embedded in. <style type=&quot;text/css“> p { color: #00f; } </style> External styles External styles are styles that are written in a separate document and then attached to various documents. External style sheets can affect any document they are attached to. <link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot; />
  • 5. CSS Best Practices Use a Reset Resets essentially eliminate browser inconsistencies such as heights, font sizes, margins, headings, etc. The reset allows your layout look consistent in all browsers. Example: body, h1,h2,h3,h4,h5,h6,form,fieldset,input,textarea,p { margin:0; padding:0; } table { border-collapse:collapse; border-spacing:0; } fieldset,img { border:0; } ol,ul { list-style:none; }
  • 6. CSS Best Practices Organize the Stylesheet with a logical Structure lay your stylesheet out in a way that allows you to quickly find parts of your code. So, an example stylesheet might be ordered like this: Generic classes (body, a, p, h1, etc.) /****** header *********/ styles goes here... /****** header End*********/ /****** main content *********/ styles goes here... /****** main content End*********/ /****** footer *********/ styles go here... /****** footer End *********/ /****** common*********/ styles go here... /****** common End *********/
  • 7. CSS Best Practices Make it Readable The readability of your CSS is incredibly important, though most people overlook why it's important. Great readability of your CSS makes it much easier to maintain in the future, as you'll be able to find elements quicker. Also, you'll never know who might need to look at your code later on. All on one line .content { background: red; padding: 2em; border: 1px solid black; } on different line .content { background: red; padding: 2em; border: 1px solid black; }
  • 8. CSS Best Practices Keep it Consistent Along the lines of keeping your code readable is making sure that the CSS is consistent. develop your own &quot;sub-language&quot; of CSS that allows you to quickly name things. There are certain classes that I create in nearly every application, and I use the same name each time. For example, I use &quot;.dbfl&quot; to float divs to the left. Good Example .dbfl { display:block; float:left; } .dbfr { display:block; float:right; } Bad Example .dbfl { display:block; float:left; } .dbfr { float:right; display:block; }
  • 9. CSS Best Practices Combine Elements Elements in a stylesheet sometimes share properties. Instead of re-writing the same properties just combine them. For example, your h1, h2, and h3 elements might all share the same font and color: h1, h2, h3 {font-family: tahoma, color: #333}
  • 10. CSS Best Practices Use Multiple Classes Sometimes it's beneficial to add multiple classes to an element. Let's say that you have a <div> having class &quot;box&quot; which defines color and font properties . <div class=&quot;box&quot;></div> Now you want to float it right, and you've already got a class . right in your CSS that floats everything to the right. You can simply add an extra class in the declaration, like so: <div class=&quot;box right&quot;></div>
  • 11. CSS Best Practices Use Shorthand while declarations Comment your CSS Avoid Using Inline Styles
  • 12. CSS Best Practices Validate your CSS Validating your CSS does more than give a sense of pride: it helps you quickly spot errors in your code. Validation Service http://jigsaw.w3.org/css-validator/