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)

CSS
CSSCSS
CSS
seedinteractive
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
priyadharshini murugan
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
Evolution Network
 
Css introduction
Css   introductionCss   introduction
Css introduction
AbhishekMondal42
 
Week 12 CSS - Review from last week
Week 12 CSS - Review from last weekWeek 12 CSS - Review from last week
Week 12 CSS - Review from last week
Katherine McCurdy-Lapierre, R.G.D.
 
CSS
CSSCSS
CSS
anandha ganesh
 
Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)Cascading Style Sheets (CSS)
Cascading Style Sheets (CSS)
Harshil Darji
 
Web Design, Lesson Plan: Classes and IDs
Web Design, Lesson Plan: Classes and IDsWeb Design, Lesson Plan: Classes and IDs
Web Design, Lesson Plan: Classes and IDs
Steve Kinney
 
Html css
Html cssHtml css
Html css
kanakaiah kedam
 
Html Expression Web
Html Expression WebHtml Expression Web
Html Expression Web
Mark Frydenberg
 
INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2INFO3775 Chapter 2 Part 2
INFO3775 Chapter 2 Part 2
Jeff Byrnes
 
Week3 css
Week3 cssWeek3 css
Week3 css
Rowena LI
 
CSS introduction
CSS introductionCSS introduction
CSS introduction
CloudTech 
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
Swati Sharma
 
Css
CssCss
Css
Anuj Singh Rajput
 

Viewers also liked (8)

Eng Abdullah Allam Cv
Eng Abdullah Allam CvEng Abdullah Allam Cv
Eng Abdullah Allam Cv
abdo366
 
Webtop
WebtopWebtop
Webtop
nish_d1
 
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
Orange Dev
 
2013 2014 ieee btech mtech dotnet projects richbraintechnologies
2013 2014 ieee btech mtech dotnet projects richbraintechnologies2013 2014 ieee btech mtech dotnet projects richbraintechnologies
2013 2014 ieee btech mtech dotnet projects richbraintechnologies
IEEEBTECHMTECHPROJECTS
 
Words
WordsWords
Words
C Russo
 
Flexible DataSync: Fuel for new business opportunities
Flexible DataSync: Fuel for new business opportunitiesFlexible DataSync: Fuel for new business opportunities
Flexible DataSync: Fuel for new business opportunities
Orange Dev
 
Meeting Point Webtop
Meeting Point WebtopMeeting Point Webtop
Meeting Point Webtop
Jeff Mowatt
 
Eng Abdullah Allam Cv
Eng Abdullah Allam CvEng Abdullah Allam Cv
Eng Abdullah Allam Cv
abdo366
 
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
developing Android and HTML5 apps for the Motorola ATRIX - Taking advantage o...
Orange Dev
 
2013 2014 ieee btech mtech dotnet projects richbraintechnologies
2013 2014 ieee btech mtech dotnet projects richbraintechnologies2013 2014 ieee btech mtech dotnet projects richbraintechnologies
2013 2014 ieee btech mtech dotnet projects richbraintechnologies
IEEEBTECHMTECHPROJECTS
 
Flexible DataSync: Fuel for new business opportunities
Flexible DataSync: Fuel for new business opportunitiesFlexible DataSync: Fuel for new business opportunities
Flexible DataSync: Fuel for new business opportunities
Orange Dev
 
Meeting Point Webtop
Meeting Point WebtopMeeting Point Webtop
Meeting Point Webtop
Jeff Mowatt
 

Similar to Css Best Practices (20)

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
Sanjoy Kr. Paul
 
Html & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshopHtml & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
Advanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & EfficiencyAdvanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS Troubleshooting
Denise Jacobs
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
WordPress Memphis
 
Maintainable CSS
Maintainable CSSMaintainable CSS
Maintainable CSS
Stephen Hay
 
CSS
CSSCSS
CSS
Md. Sirajus Salayhin
 
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
10Clouds
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
CSS Best practices
CSS Best practicesCSS Best practices
CSS Best practices
José Teixidó
 
Modern front end development
Modern front end developmentModern front end development
Modern front end development
Tricode (part of Dept)
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
Russ Weakley
 
Css
CssCss
Css
NIRMAL FELIX
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventionsHTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
Make Css easy(part:2) : easy tips for css(part:2)
Make Css easy(part:2) : easy tips for css(part:2)Make Css easy(part:2) : easy tips for css(part:2)
Make Css easy(part:2) : easy tips for css(part:2)
shabab shihan
 
Basics Of Css And Some Common Mistakes
Basics Of Css And Some Common MistakesBasics Of Css And Some Common Mistakes
Basics Of Css And Some Common Mistakes
sanjay2211
 
Css
CssCss
Css
Balakumaran Arunachalam
 
Efficient, maintainable CSS
Efficient, maintainable CSSEfficient, maintainable CSS
Efficient, maintainable CSS
Russ Weakley
 
Introduction to Frontend Development - Session 2 - CSS Fundamentals
Introduction to Frontend Development - Session 2 - CSS FundamentalsIntroduction to Frontend Development - Session 2 - CSS Fundamentals
Introduction to Frontend Development - Session 2 - CSS Fundamentals
Kalin Chernev
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad
 
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
Sanjoy Kr. Paul
 
Html & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshopHtml & CSS - Best practices 2-hour-workshop
Html & CSS - Best practices 2-hour-workshop
Vero Rebagliatte
 
Advanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & EfficiencyAdvanced CSS Troubleshooting & Efficiency
Advanced CSS Troubleshooting & Efficiency
Denise Jacobs
 
Advanced CSS Troubleshooting
Advanced CSS TroubleshootingAdvanced CSS Troubleshooting
Advanced CSS Troubleshooting
Denise Jacobs
 
Maintainable CSS
Maintainable CSSMaintainable CSS
Maintainable CSS
Stephen Hay
 
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
10Clouds
 
How Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) WorksHow Cascading Style Sheets (CSS) Works
How Cascading Style Sheets (CSS) Works
Amit Tyagi
 
HTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventionsHTML5, CSS, JavaScript Style guide and coding conventions
HTML5, CSS, JavaScript Style guide and coding conventions
Knoldus Inc.
 
Make Css easy(part:2) : easy tips for css(part:2)
Make Css easy(part:2) : easy tips for css(part:2)Make Css easy(part:2) : easy tips for css(part:2)
Make Css easy(part:2) : easy tips for css(part:2)
shabab shihan
 
Basics Of Css And Some Common Mistakes
Basics Of Css And Some Common MistakesBasics Of Css And Some Common Mistakes
Basics Of Css And Some Common Mistakes
sanjay2211
 
Efficient, maintainable CSS
Efficient, maintainable CSSEfficient, maintainable CSS
Efficient, maintainable CSS
Russ Weakley
 
Introduction to Frontend Development - Session 2 - CSS Fundamentals
Introduction to Frontend Development - Session 2 - CSS FundamentalsIntroduction to Frontend Development - Session 2 - CSS Fundamentals
Introduction to Frontend Development - Session 2 - CSS Fundamentals
Kalin Chernev
 
CSS Methodology
CSS MethodologyCSS Methodology
CSS Methodology
Zohar Arad
 

Recently uploaded (20)

FL Studio Producer Edition Crack + Full Version [Latest]
FL Studio Producer Edition Crack + Full Version [Latest]FL Studio Producer Edition Crack + Full Version [Latest]
FL Studio Producer Edition Crack + Full Version [Latest]
Mudasir
 
The Canvas of Creative Mastery Newsletter_May 2025
The Canvas of Creative Mastery Newsletter_May 2025The Canvas of Creative Mastery Newsletter_May 2025
The Canvas of Creative Mastery Newsletter_May 2025
AmirYakdi
 
Total Uninstall Pro 7 Crack Free Download [Latest]
Total Uninstall Pro 7 Crack Free Download [Latest]Total Uninstall Pro 7 Crack Free Download [Latest]
Total Uninstall Pro 7 Crack Free Download [Latest]
Designer
 
Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]
Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]
Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]
Developer
 
Best Website Designing Company In Delhi NCR
Best Website Designing Company In Delhi NCRBest Website Designing Company In Delhi NCR
Best Website Designing Company In Delhi NCR
Etoile Info Solutions
 
FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025
FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025
FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025
Designer
 
Xiaomi Flash Tool Free Download 2025 for All Versions
Xiaomi Flash Tool Free Download 2025 for All VersionsXiaomi Flash Tool Free Download 2025 for All Versions
Xiaomi Flash Tool Free Download 2025 for All Versions
Designer
 
Movavi Video Suite 22.0.1 Crack + Activation Key 2025
Movavi Video Suite 22.0.1 Crack + Activation Key 2025Movavi Video Suite 22.0.1 Crack + Activation Key 2025
Movavi Video Suite 22.0.1 Crack + Activation Key 2025
Designer
 
Windows Video Converter 2025 v9.7.0.0 Full Crack 2025
Windows Video Converter 2025 v9.7.0.0 Full Crack 2025Windows Video Converter 2025 v9.7.0.0 Full Crack 2025
Windows Video Converter 2025 v9.7.0.0 Full Crack 2025
Yahoo
 
Homedecor Furniture Warehouse presentation
Homedecor Furniture Warehouse presentationHomedecor Furniture Warehouse presentation
Homedecor Furniture Warehouse presentation
Home Decor
 
AVS Video Converter 12.1.5.673 Full Crack Download [Latest]
AVS Video Converter 12.1.5.673 Full Crack Download [Latest]AVS Video Converter 12.1.5.673 Full Crack Download [Latest]
AVS Video Converter 12.1.5.673 Full Crack Download [Latest]
Google
 
Keyword Researcher Pro 13.180 Full Crack 2025
Keyword Researcher Pro 13.180 Full Crack 2025Keyword Researcher Pro 13.180 Full Crack 2025
Keyword Researcher Pro 13.180 Full Crack 2025
Designer
 
GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]
GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]
GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]
Designer
 
NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]
NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]
NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]
Google
 
Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]
Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]
Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]
Developer
 
CleanMyPC Crack 1.12.0.2113 + Activation Code 2025
CleanMyPC Crack 1.12.0.2113 + Activation Code 2025CleanMyPC Crack 1.12.0.2113 + Activation Code 2025
CleanMyPC Crack 1.12.0.2113 + Activation Code 2025
Yahoo
 
Supplier Sourcing Sample Work of Maisie.pdf
Supplier Sourcing Sample Work of Maisie.pdfSupplier Sourcing Sample Work of Maisie.pdf
Supplier Sourcing Sample Work of Maisie.pdf
MelissaMaisieVillanu
 
Unit IV-Logic Gates.pdf gsgagagagagggggg
Unit IV-Logic Gates.pdf gsgagagagaggggggUnit IV-Logic Gates.pdf gsgagagagagggggg
Unit IV-Logic Gates.pdf gsgagagagagggggg
briosmarttv
 
Minahil Mushtaq's Creative Portfolio 2024
Minahil Mushtaq's Creative Portfolio 2024Minahil Mushtaq's Creative Portfolio 2024
Minahil Mushtaq's Creative Portfolio 2024
MinahilMushtaq2
 
OntologyDuVerneayBigDesign2025_May28.pptx
OntologyDuVerneayBigDesign2025_May28.pptxOntologyDuVerneayBigDesign2025_May28.pptx
OntologyDuVerneayBigDesign2025_May28.pptx
Jessica DuVerneay
 
FL Studio Producer Edition Crack + Full Version [Latest]
FL Studio Producer Edition Crack + Full Version [Latest]FL Studio Producer Edition Crack + Full Version [Latest]
FL Studio Producer Edition Crack + Full Version [Latest]
Mudasir
 
The Canvas of Creative Mastery Newsletter_May 2025
The Canvas of Creative Mastery Newsletter_May 2025The Canvas of Creative Mastery Newsletter_May 2025
The Canvas of Creative Mastery Newsletter_May 2025
AmirYakdi
 
Total Uninstall Pro 7 Crack Free Download [Latest]
Total Uninstall Pro 7 Crack Free Download [Latest]Total Uninstall Pro 7 Crack Free Download [Latest]
Total Uninstall Pro 7 Crack Free Download [Latest]
Designer
 
Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]
Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]
Movavi Slideshow Maker 7.0.1 Crack + Activation Key [Latest]
Developer
 
Best Website Designing Company In Delhi NCR
Best Website Designing Company In Delhi NCRBest Website Designing Company In Delhi NCR
Best Website Designing Company In Delhi NCR
Etoile Info Solutions
 
FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025
FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025
FonePaw iPhone Data Recovery 8.5.0 Full Crack 2025
Designer
 
Xiaomi Flash Tool Free Download 2025 for All Versions
Xiaomi Flash Tool Free Download 2025 for All VersionsXiaomi Flash Tool Free Download 2025 for All Versions
Xiaomi Flash Tool Free Download 2025 for All Versions
Designer
 
Movavi Video Suite 22.0.1 Crack + Activation Key 2025
Movavi Video Suite 22.0.1 Crack + Activation Key 2025Movavi Video Suite 22.0.1 Crack + Activation Key 2025
Movavi Video Suite 22.0.1 Crack + Activation Key 2025
Designer
 
Windows Video Converter 2025 v9.7.0.0 Full Crack 2025
Windows Video Converter 2025 v9.7.0.0 Full Crack 2025Windows Video Converter 2025 v9.7.0.0 Full Crack 2025
Windows Video Converter 2025 v9.7.0.0 Full Crack 2025
Yahoo
 
Homedecor Furniture Warehouse presentation
Homedecor Furniture Warehouse presentationHomedecor Furniture Warehouse presentation
Homedecor Furniture Warehouse presentation
Home Decor
 
AVS Video Converter 12.1.5.673 Full Crack Download [Latest]
AVS Video Converter 12.1.5.673 Full Crack Download [Latest]AVS Video Converter 12.1.5.673 Full Crack Download [Latest]
AVS Video Converter 12.1.5.673 Full Crack Download [Latest]
Google
 
Keyword Researcher Pro 13.180 Full Crack 2025
Keyword Researcher Pro 13.180 Full Crack 2025Keyword Researcher Pro 13.180 Full Crack 2025
Keyword Researcher Pro 13.180 Full Crack 2025
Designer
 
GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]
GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]
GlarySoft Malware Hunter Pro 1.117.0.710 with Crack [Latest]
Designer
 
NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]
NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]
NoteBurner Spotify Music Converter 2.2.4 with Crack [Latest]
Google
 
Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]
Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]
Auslogics Disk Defrag Pro 10.0.0.1 Crack + Key Download [Latest]
Developer
 
CleanMyPC Crack 1.12.0.2113 + Activation Code 2025
CleanMyPC Crack 1.12.0.2113 + Activation Code 2025CleanMyPC Crack 1.12.0.2113 + Activation Code 2025
CleanMyPC Crack 1.12.0.2113 + Activation Code 2025
Yahoo
 
Supplier Sourcing Sample Work of Maisie.pdf
Supplier Sourcing Sample Work of Maisie.pdfSupplier Sourcing Sample Work of Maisie.pdf
Supplier Sourcing Sample Work of Maisie.pdf
MelissaMaisieVillanu
 
Unit IV-Logic Gates.pdf gsgagagagagggggg
Unit IV-Logic Gates.pdf gsgagagagaggggggUnit IV-Logic Gates.pdf gsgagagagagggggg
Unit IV-Logic Gates.pdf gsgagagagagggggg
briosmarttv
 
Minahil Mushtaq's Creative Portfolio 2024
Minahil Mushtaq's Creative Portfolio 2024Minahil Mushtaq's Creative Portfolio 2024
Minahil Mushtaq's Creative Portfolio 2024
MinahilMushtaq2
 
OntologyDuVerneayBigDesign2025_May28.pptx
OntologyDuVerneayBigDesign2025_May28.pptxOntologyDuVerneayBigDesign2025_May28.pptx
OntologyDuVerneayBigDesign2025_May28.pptx
Jessica DuVerneay
 

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/