SlideShare a Scribd company logo
Structuring your CSS for
maintainability
Class-9: Rules and guile lines to write CSS
Sanjoy K. Paul
Lead Application Developer | Software Architect | DevOps | Trainer
www.SanjoyPaul.com | skpaul@DevsStation.com | +880-1511-927992
HTML or CSS First?
KISS - Keep It Simple & Short(hand).
DRY - Donโ€™t Repeat Yourself.
IMP - Important! is not that important.
- Make It Readable
- Keep It Consistent
- Use a Reset
TDS - Top-Down Structure
- Comment is the savier
- No Inline
Organizing your CSS
As you start work on larger stylesheets and big project with a team, you will
discover that maintaining a huge css file can be challenging.
So, we will go through some best practices for writing css that will help us to
maintain the css project easily.
How to keep your stylesheet organized and tidy?
Does our project have a coding style guide?
- If we are working in a team or existing project? then
- First thing to check is whether the project has an existing style guide for CSS?
- The team style guide should always win over your own personal preferences.
- There often isn't a right or wrong way to do things, but consistency is
important.
Keep it consistent
- set the rules for the project or are working alone,
- then the most important thing to do is to keep things consistent.
- Consistency can be applied in all sorts of ways,
- Using the same naming conventions for classes,
- choosing one method of describing color,
- or maintaining consistent formatting
- for example will you use tabs or spaces to indent your code? If
spaces, how many spaces?
Keep it consistent
Pros:
- Having a set of rules you always follow
- Reduces the amount of mental overhead needed when writing
CSS, as some of the decisions are already made.
Cons:
- Sometime itโ€™s hard to maintain the consistency if you are in a
tight deadline
Formatting readable CSS:
There are a couple of ways you will see CSS formatted.
Some developers put all of the rules onto a single line
.box { background-color: #567895; }
h2 { background-color: black; color: white; }
Other developers prefer to break everything onto a
new line:
.box {
background-color: #567895;
}
h2 {
background-color: black;
color: white;
}
CSS doesn't mind which one you use. I personally find it is more readable to have each property and value pair on a new line.
Comment your CSS
Adding comments to your CSS will help
- Any future developer work with your CSS file
- Also will help you when you come back to the project after a break.
/* This is a CSS comment
It can be broken onto multiple lines. */
Comment your CSS
/* || General styles */
...
/* || Typography */
...
/* || Header and Main
Navigation */
...
- Add a block of comments between logical
sections
- It will help to locate different sections quickly
when scanning through,
- Or even give you something to search for to
jump right into that part of the CSS.
- If you use a string which won't appear in the
code you can jump from section to section by
searching for it. We can use || or --start an. ..end
Comment your CSS
We don't need to comment every single thing in our code, as much of it is self-explanatory. We only comment on the things where we make a
particular decision for a reason.
Another example: Including reference tutorial/any links as a comment. It will help us to recall in future.
/** CSS Code guideline
https://developer.mozilla.org/en-US/docs/MDN/Guidelines/Code_guidelines/CSS
*/
Example: we may have used a CSS property in a specific way to get around older browser incompatibilities.
.box {
background-color : red; /* fallback for older browsers that don't support gradients */
background-image : linear-gradient (to right, #ff0000, #aa0000);
}
Create logical sections in your stylesheet
It is a good idea to have all of the common styling first in the stylesheet. This means all of the styles which will generally
apply unless you do something special with that element. You will typically have rules set up for:
โ— body
โ— p
โ— h1, h2, h3, h4, h5
โ— ul and ol
โ— The table properties
โ— Links
Lets see some code...
Using CSS Vendor Pre๏ฌxed
Some of these CSS browser pre๏ฌxes have been listed below:
iOS: -webkit-
Safari: -webkit-
Firefox: -moz-
Chrome: -webkit-
Opera: -o-
MS/IE/Edge: -ms-
Each browser have a set of speci๏ฌcations related to any style. This is one of the reasons why browser pre๏ฌxed are
implemented in order to ensure that these browsers support any of the speci๏ฌc features or style that we would like to
implement.
If we are planning to add a CSS 3 transition to any of our CSS code, then
we will can use transition property and implement a vendor pre๏ฌx with it.
Below is the code for the same:
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-ms-transition: all 1s ease;
-o-transition: all 1s ease;
transition: all 1s ease;
Do Not Be Too Speci๏ฌc & Chain Classes
article.main p.box {
border: 1px solid #ccc;
}
.box {
border: 1px solid #ccc;
}
.btn.submit {
border: 1px solid #ccc;
}
.btn{
border: 1px solid #ccc;
}
.submit {
Background: #FF0;
}
Break large stylesheets into multiple smaller ones!??
For example, you might have an online store as part of the site, with a lot of CSS
used only for styling the product listings and forms needed for the store. It would
make sense to have those things in a di๏ฌ€erent stylesheet, only linked to on store
pages.
This can make it easier to keep your CSS organized, and also means that if multiple
people are working on the CSS you will have fewer situations where two people
need to work on the same stylesheet at once, leading to con๏ฌ‚icts in source control.
CSS methodologies
- OOCSS (Object-Oriented CSS): Treats page elements as objects, giving all objects classes, treating the objectsโ€™ classes as single
entities in style sheets, and taking it from there.. https://github.com/stubbornella/oocss/wiki
- BEM (Block, Element, Modi๏ฌer): Block Element Modi๏ฌer is a methodology that helps you create reusable components and code
sharing in front-end development. - https://css-tricks.com/bem-101/
- SMACSS (Scalable and Modular Architecture for CSS): a ๏ฌ‚exible guide to developing sites small and large. Arguably
becoming one of the most useful contributions to front-end discussions in years. - http://smacss.com/
- Atomic CSS: is the approach to CSS architecture that favors small, single-purpose classes with names based on visual function. -
https://acss.io/
- ITCSS - Inverted Triangle CSS: A sane, scalable, managed CSS architecture achieved with mindful CSS code organization. -
https://itcss.io/
HTML!
What we do to write HTML code?
- Always Declare Document Type (<!DOCTYPE html>)
- Use Lowercase โ€œElementโ€ and โ€œAttributeโ€ Names. Donโ€™t mix uppercase and lowercase (body, div, article)
- Always Quote Attribute Values
- Always Specify โ€œaltโ€ for Images (and also width and height)
- Close All HTML Elements
- Close Empty HTML Elements? (<meta charset="utf-8" />, required in XML and XHTML)
- Never Skip the <title> Element (SEO)
- Add the lang and charset attribute, both are important for SEO indexing (SEO, <html lang="en-us" />)
- Meta Datas (key, description, og and )
- Avoid Long Code Lines
- Spaces and Equal Signs
- Blank Lines and Indentation. Donโ€™t use it unnecessarily.
- Omitting <html>, <body>, <head> tags?
- Viewport
- Create Your HTML First
- It will be updated and continued with time..
Summary
KISS - Keep It Simple & Short(hand).
DRY - Donโ€™t Repeat Yourself.
IMP - Important! is not that important.
- Make It Readable
- Keep It Consistent
- Use a Reset??
TDS - Top-Down Structure
- The Comment is the savior
- No Inline
- Maintain the Spaci๏ฌcity (*, tag, class, id)
- ...
Validating your CSS!
You can always use the W3C free CSS validator to examine whether your CSS code has been organized and structured
appropriately.
One of the other bene๏ฌts of using it is to help you ๏ฌnd errors within your stylesheet.
This will save your time to troubleshooting comparing to doing it manually.
Markup Validation Tool: https://validator.w3.org/
CSS Validation Tool: https://jigsaw.w3.org/css-validator/
Browser Compatibility Testing Tool: https://app.crossbrowsertesting.com/ https://www.lambdatest.com/
Interested to know more?
- https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Organizing#create_logical_sections_in_your_stylesheet
- https://developer.mozilla.org/en-US/docs/MDN/Guidelines/Code_guidelines/CSS
- https://www.w3schools.com/html/html5_syntax.asp
- https://www.valoremreply.com/post/5_css_methodologies/
- https://cssguidelin.es/
- https://www.sitepoint.com/optimizing-css-performance/
Question?
Sanjoy K. Paul
Lead Application Developer | Software Architect | DevOps | Trainer
www.SanjoyPaul.com | skpaul@DevsStation.com | +880-1511-927992
Ad

More Related Content

What's hot (20)

Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
danpaquette
ย 
The Dark Arts of CSS
The Dark Arts of CSSThe Dark Arts of CSS
The Dark Arts of CSS
SiddharthBorderwala
ย 
Basics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPointBasics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPoint
Sahil Gandhi
ย 
Lecture2 CSS1
Lecture2  CSS1Lecture2  CSS1
Lecture2 CSS1
Sur College of Applied Sciences
ย 
Spectrum 2015 going online with style - an intro to css
Spectrum 2015   going online with style - an intro to cssSpectrum 2015   going online with style - an intro to css
Spectrum 2015 going online with style - an intro to css
Neil Perlin
ย 
Front End Best Practices
Front End Best PracticesFront End Best Practices
Front End Best Practices
Holger Bartel
ย 
Css home
Css   homeCss   home
Css home
AbhishekMondal42
ย 
Full
FullFull
Full
sanjaykhan33
ย 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
Suzette Franck
ย 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
William Myers
ย 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tips
Chris Love
ย 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
ย 
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
Hatem Mahmoud
ย 
Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15
Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15
Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15
Andy McIlwain
ย 
Modern Front-End Development
Modern Front-End DevelopmentModern Front-End Development
Modern Front-End Development
mwrather
ย 
Css3
Css3Css3
Css3
Vladimir Varun
ย 
Intro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersIntro to Sass for WordPress Developers
Intro to Sass for WordPress Developers
Suzette Franck
ย 
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeMinimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Suzanne Dergacheva
ย 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
Vittorio Vittori
ย 
HTML/CSS for WordPress
HTML/CSS for WordPressHTML/CSS for WordPress
HTML/CSS for WordPress
Kanchha kaji Prajapati
ย 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
danpaquette
ย 
Basics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPointBasics of Front End Web Dev PowerPoint
Basics of Front End Web Dev PowerPoint
Sahil Gandhi
ย 
Spectrum 2015 going online with style - an intro to css
Spectrum 2015   going online with style - an intro to cssSpectrum 2015   going online with style - an intro to css
Spectrum 2015 going online with style - an intro to css
Neil Perlin
ย 
Front End Best Practices
Front End Best PracticesFront End Best Practices
Front End Best Practices
Holger Bartel
ย 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
Suzette Franck
ย 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
William Myers
ย 
Css best practices style guide and tips
Css best practices style guide and tipsCss best practices style guide and tips
Css best practices style guide and tips
Chris Love
ย 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Erin M. Kidwell
ย 
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
Hatem Mahmoud
ย 
Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15
Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15
Crafting Custom CSS @ PodCamp Toronto 2015 #PCTO15
Andy McIlwain
ย 
Modern Front-End Development
Modern Front-End DevelopmentModern Front-End Development
Modern Front-End Development
mwrather
ย 
Intro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersIntro to Sass for WordPress Developers
Intro to Sass for WordPress Developers
Suzette Franck
ย 
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 ThemeMinimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Minimalist Theming: How to Build a Lean, Mean Drupal 8 Theme
Suzanne Dergacheva
ย 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
Vittorio Vittori
ย 

Similar to Structuring your CSS for maintainability: rules and guile lines to write CSS (20)

INTRODUCTIONS OF CSS
INTRODUCTIONS OF CSSINTRODUCTIONS OF CSS
INTRODUCTIONS OF CSS
SURYANARAYANBISWAL1
ย 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
butest
ย 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
butest
ย 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
nikhilsh66131
ย 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
QA TrainingHub
ย 
Chapter 3 - CSS.pdf
Chapter 3 - CSS.pdfChapter 3 - CSS.pdf
Chapter 3 - CSS.pdf
wubiederebe1
ย 
Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
Gareth Saunders
ย 
The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
jackchenvlo
ย 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding Standards
Saajan Maharjan
ย 
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
Stefan Bauer
ย 
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
ย 
Cashcading stylesheets
Cashcading stylesheetsCashcading stylesheets
Cashcading stylesheets
reddivarihareesh
ย 
Developing for the unknown lavacon
Developing for the unknown   lavaconDeveloping for the unknown   lavacon
Developing for the unknown lavacon
Neil Perlin
ย 
Developing for the unknown lavacon
Developing for the unknown   lavaconDeveloping for the unknown   lavacon
Developing for the unknown lavacon
Neil Perlin
ย 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
ย 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
tutorialsruby
ย 
Css
CssCss
Css
Jahid Blackrose
ย 
An Introduction to CSS Frameworks
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS Frameworks
Adrian Westlake
ย 
Vskills certified css designer Notes
Vskills certified css designer NotesVskills certified css designer Notes
Vskills certified css designer Notes
Vskills
ย 
Intermediate Web Design
Intermediate Web DesignIntermediate Web Design
Intermediate Web Design
mlincol2
ย 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
butest
ย 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
butest
ย 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
nikhilsh66131
ย 
Css training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentialsCss training tutorial css3 &amp; css4 essentials
Css training tutorial css3 &amp; css4 essentials
QA TrainingHub
ย 
Chapter 3 - CSS.pdf
Chapter 3 - CSS.pdfChapter 3 - CSS.pdf
Chapter 3 - CSS.pdf
wubiederebe1
ย 
Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
Gareth Saunders
ย 
The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
jackchenvlo
ย 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding Standards
Saajan Maharjan
ย 
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
SPS Oslo - Stop your SharePoint CSS becoming a di-sass-ter today!
Stefan Bauer
ย 
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Styling Your Web Pages with Cascading Style Sheets / EDU course / University ...
Patrick Lauke
ย 
Cashcading stylesheets
Cashcading stylesheetsCashcading stylesheets
Cashcading stylesheets
reddivarihareesh
ย 
Developing for the unknown lavacon
Developing for the unknown   lavaconDeveloping for the unknown   lavacon
Developing for the unknown lavacon
Neil Perlin
ย 
Developing for the unknown lavacon
Developing for the unknown   lavaconDeveloping for the unknown   lavacon
Developing for the unknown lavacon
Neil Perlin
ย 
An Introduction to CSS Frameworks
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS Frameworks
Adrian Westlake
ย 
Vskills certified css designer Notes
Vskills certified css designer NotesVskills certified css designer Notes
Vskills certified css designer Notes
Vskills
ย 
Intermediate Web Design
Intermediate Web DesignIntermediate Web Design
Intermediate Web Design
mlincol2
ย 
Ad

Recently uploaded (20)

Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
ย 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
ย 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
ย 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
ย 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
ย 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
ย 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
ย 
Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
ย 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
ย 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
ย 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
ย 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
ย 
Rock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning JourneyRock, Paper, Scissors: An Apex Map Learning Journey
Rock, Paper, Scissors: An Apex Map Learning Journey
Lynda Kane
ย 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
ย 
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything โ€“ Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
ย 
"PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System""PHP and MySQL CRUD Operations for Student Management System"
"PHP and MySQL CRUD Operations for Student Management System"
Jainul Musani
ย 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
ย 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
ย 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
ย 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
ย 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
ย 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
ย 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
ย 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
ย 
Hands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordDataHands On: Create a Lightning Aura Component with force:RecordData
Hands On: Create a Lightning Aura Component with force:RecordData
Lynda Kane
ย 
Buckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug LogsBuckeye Dreamin' 2023: De-fogging Debug Logs
Buckeye Dreamin' 2023: De-fogging Debug Logs
Lynda Kane
ย 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
ย 
Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.Network Security. Different aspects of Network Security.
Network Security. Different aspects of Network Security.
gregtap1
ย 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
ย 
Ad

Structuring your CSS for maintainability: rules and guile lines to write CSS

  • 1. Structuring your CSS for maintainability Class-9: Rules and guile lines to write CSS Sanjoy K. Paul Lead Application Developer | Software Architect | DevOps | Trainer www.SanjoyPaul.com | skpaul@DevsStation.com | +880-1511-927992
  • 2. HTML or CSS First?
  • 3. KISS - Keep It Simple & Short(hand). DRY - Donโ€™t Repeat Yourself. IMP - Important! is not that important. - Make It Readable - Keep It Consistent - Use a Reset TDS - Top-Down Structure - Comment is the savier - No Inline
  • 4. Organizing your CSS As you start work on larger stylesheets and big project with a team, you will discover that maintaining a huge css file can be challenging. So, we will go through some best practices for writing css that will help us to maintain the css project easily.
  • 5. How to keep your stylesheet organized and tidy?
  • 6. Does our project have a coding style guide? - If we are working in a team or existing project? then - First thing to check is whether the project has an existing style guide for CSS? - The team style guide should always win over your own personal preferences. - There often isn't a right or wrong way to do things, but consistency is important.
  • 7. Keep it consistent - set the rules for the project or are working alone, - then the most important thing to do is to keep things consistent. - Consistency can be applied in all sorts of ways, - Using the same naming conventions for classes, - choosing one method of describing color, - or maintaining consistent formatting - for example will you use tabs or spaces to indent your code? If spaces, how many spaces?
  • 8. Keep it consistent Pros: - Having a set of rules you always follow - Reduces the amount of mental overhead needed when writing CSS, as some of the decisions are already made. Cons: - Sometime itโ€™s hard to maintain the consistency if you are in a tight deadline
  • 9. Formatting readable CSS: There are a couple of ways you will see CSS formatted. Some developers put all of the rules onto a single line .box { background-color: #567895; } h2 { background-color: black; color: white; } Other developers prefer to break everything onto a new line: .box { background-color: #567895; } h2 { background-color: black; color: white; } CSS doesn't mind which one you use. I personally find it is more readable to have each property and value pair on a new line.
  • 10. Comment your CSS Adding comments to your CSS will help - Any future developer work with your CSS file - Also will help you when you come back to the project after a break. /* This is a CSS comment It can be broken onto multiple lines. */
  • 11. Comment your CSS /* || General styles */ ... /* || Typography */ ... /* || Header and Main Navigation */ ... - Add a block of comments between logical sections - It will help to locate different sections quickly when scanning through, - Or even give you something to search for to jump right into that part of the CSS. - If you use a string which won't appear in the code you can jump from section to section by searching for it. We can use || or --start an. ..end
  • 12. Comment your CSS We don't need to comment every single thing in our code, as much of it is self-explanatory. We only comment on the things where we make a particular decision for a reason. Another example: Including reference tutorial/any links as a comment. It will help us to recall in future. /** CSS Code guideline https://developer.mozilla.org/en-US/docs/MDN/Guidelines/Code_guidelines/CSS */ Example: we may have used a CSS property in a specific way to get around older browser incompatibilities. .box { background-color : red; /* fallback for older browsers that don't support gradients */ background-image : linear-gradient (to right, #ff0000, #aa0000); }
  • 13. Create logical sections in your stylesheet It is a good idea to have all of the common styling first in the stylesheet. This means all of the styles which will generally apply unless you do something special with that element. You will typically have rules set up for: โ— body โ— p โ— h1, h2, h3, h4, h5 โ— ul and ol โ— The table properties โ— Links Lets see some code...
  • 14. Using CSS Vendor Pre๏ฌxed Some of these CSS browser pre๏ฌxes have been listed below: iOS: -webkit- Safari: -webkit- Firefox: -moz- Chrome: -webkit- Opera: -o- MS/IE/Edge: -ms- Each browser have a set of speci๏ฌcations related to any style. This is one of the reasons why browser pre๏ฌxed are implemented in order to ensure that these browsers support any of the speci๏ฌc features or style that we would like to implement. If we are planning to add a CSS 3 transition to any of our CSS code, then we will can use transition property and implement a vendor pre๏ฌx with it. Below is the code for the same: -webkit-transition: all 1s ease; -moz-transition: all 1s ease; -ms-transition: all 1s ease; -o-transition: all 1s ease; transition: all 1s ease;
  • 15. Do Not Be Too Speci๏ฌc & Chain Classes article.main p.box { border: 1px solid #ccc; } .box { border: 1px solid #ccc; } .btn.submit { border: 1px solid #ccc; } .btn{ border: 1px solid #ccc; } .submit { Background: #FF0; }
  • 16. Break large stylesheets into multiple smaller ones!?? For example, you might have an online store as part of the site, with a lot of CSS used only for styling the product listings and forms needed for the store. It would make sense to have those things in a di๏ฌ€erent stylesheet, only linked to on store pages. This can make it easier to keep your CSS organized, and also means that if multiple people are working on the CSS you will have fewer situations where two people need to work on the same stylesheet at once, leading to con๏ฌ‚icts in source control.
  • 17. CSS methodologies - OOCSS (Object-Oriented CSS): Treats page elements as objects, giving all objects classes, treating the objectsโ€™ classes as single entities in style sheets, and taking it from there.. https://github.com/stubbornella/oocss/wiki - BEM (Block, Element, Modi๏ฌer): Block Element Modi๏ฌer is a methodology that helps you create reusable components and code sharing in front-end development. - https://css-tricks.com/bem-101/ - SMACSS (Scalable and Modular Architecture for CSS): a ๏ฌ‚exible guide to developing sites small and large. Arguably becoming one of the most useful contributions to front-end discussions in years. - http://smacss.com/ - Atomic CSS: is the approach to CSS architecture that favors small, single-purpose classes with names based on visual function. - https://acss.io/ - ITCSS - Inverted Triangle CSS: A sane, scalable, managed CSS architecture achieved with mindful CSS code organization. - https://itcss.io/
  • 18. HTML! What we do to write HTML code? - Always Declare Document Type (<!DOCTYPE html>) - Use Lowercase โ€œElementโ€ and โ€œAttributeโ€ Names. Donโ€™t mix uppercase and lowercase (body, div, article) - Always Quote Attribute Values - Always Specify โ€œaltโ€ for Images (and also width and height) - Close All HTML Elements - Close Empty HTML Elements? (<meta charset="utf-8" />, required in XML and XHTML) - Never Skip the <title> Element (SEO) - Add the lang and charset attribute, both are important for SEO indexing (SEO, <html lang="en-us" />) - Meta Datas (key, description, og and ) - Avoid Long Code Lines - Spaces and Equal Signs - Blank Lines and Indentation. Donโ€™t use it unnecessarily. - Omitting <html>, <body>, <head> tags? - Viewport - Create Your HTML First - It will be updated and continued with time..
  • 19. Summary KISS - Keep It Simple & Short(hand). DRY - Donโ€™t Repeat Yourself. IMP - Important! is not that important. - Make It Readable - Keep It Consistent - Use a Reset?? TDS - Top-Down Structure - The Comment is the savior - No Inline - Maintain the Spaci๏ฌcity (*, tag, class, id) - ...
  • 20. Validating your CSS! You can always use the W3C free CSS validator to examine whether your CSS code has been organized and structured appropriately. One of the other bene๏ฌts of using it is to help you ๏ฌnd errors within your stylesheet. This will save your time to troubleshooting comparing to doing it manually. Markup Validation Tool: https://validator.w3.org/ CSS Validation Tool: https://jigsaw.w3.org/css-validator/ Browser Compatibility Testing Tool: https://app.crossbrowsertesting.com/ https://www.lambdatest.com/
  • 21. Interested to know more? - https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Organizing#create_logical_sections_in_your_stylesheet - https://developer.mozilla.org/en-US/docs/MDN/Guidelines/Code_guidelines/CSS - https://www.w3schools.com/html/html5_syntax.asp - https://www.valoremreply.com/post/5_css_methodologies/ - https://cssguidelin.es/ - https://www.sitepoint.com/optimizing-css-performance/
  • 22. Question? Sanjoy K. Paul Lead Application Developer | Software Architect | DevOps | Trainer www.SanjoyPaul.com | skpaul@DevsStation.com | +880-1511-927992