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 Prefixed
Some of these CSS browser prefixes have been listed below:
iOS: -webkit-
Safari: -webkit-
Firefox: -moz-
Chrome: -webkit-
Opera: -o-
MS/IE/Edge: -ms-
Each browser have a set of specifications related to any style. This is one of the reasons why browser prefixed are
implemented in order to ensure that these browsers support any of the specific 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 prefix 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 Specific & 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 different 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 conflicts 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, Modifier): Block Element Modifier 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 flexible 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 Spacificity (*, 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 benefits of using it is to help you find 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

More Related Content

What's hot

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 PowerPointSahil 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 4Erin 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
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
 

What's hot (20)

Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 
The Dark Arts of CSS
The Dark Arts of CSSThe Dark Arts of CSS
The Dark Arts of CSS
 
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
 
Lecture2 CSS1
Lecture2  CSS1Lecture2  CSS1
Lecture2 CSS1
 
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
 
Front End Best Practices
Front End Best PracticesFront End Best Practices
Front End Best Practices
 
Css home
Css   homeCss   home
Css home
 
Full
FullFull
Full
 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
 
Fewd week2 slides
Fewd week2 slidesFewd week2 slides
Fewd week2 slides
 
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
 
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
 
Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02Cascading Style Sheets - Part 02
Cascading Style Sheets - Part 02
 
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
 
Modern Front-End Development
Modern Front-End DevelopmentModern Front-End Development
Modern Front-End Development
 
Css3
Css3Css3
Css3
 
Intro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersIntro to Sass for WordPress Developers
Intro to Sass for WordPress Developers
 
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
 
Teams, styles and scalable applications
Teams, styles and scalable applicationsTeams, styles and scalable applications
Teams, styles and scalable applications
 
HTML/CSS for WordPress
HTML/CSS for WordPressHTML/CSS for WordPress
HTML/CSS for WordPress
 

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

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.docbutest
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.docbutest
 
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
 

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
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
 
Intermediate Web Design.doc
Intermediate Web Design.docIntermediate Web Design.doc
Intermediate Web Design.doc
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
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
 
Chapter 3 - CSS.pdf
Chapter 3 - CSS.pdfChapter 3 - CSS.pdf
Chapter 3 - CSS.pdf
 
Using a CSS Framework
Using a CSS FrameworkUsing a CSS Framework
Using a CSS Framework
 
The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
 
HTML and CSS Coding Standards
HTML and CSS Coding StandardsHTML and CSS Coding Standards
HTML and CSS Coding Standards
 
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!
 
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 ...
 
Cashcading stylesheets
Cashcading stylesheetsCashcading stylesheets
Cashcading stylesheets
 
Developing for the unknown lavacon
Developing for the unknown   lavaconDeveloping for the unknown   lavacon
Developing for the unknown lavacon
 
Developing for the unknown lavacon
Developing for the unknown   lavaconDeveloping for the unknown   lavacon
Developing for the unknown lavacon
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
Css
CssCss
Css
 
An Introduction to CSS Frameworks
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS Frameworks
 
Vskills certified css designer Notes
Vskills certified css designer NotesVskills certified css designer Notes
Vskills certified css designer Notes
 
Intermediate Web Design
Intermediate Web DesignIntermediate Web Design
Intermediate Web Design
 

Recently uploaded

Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

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 Prefixed Some of these CSS browser prefixes have been listed below: iOS: -webkit- Safari: -webkit- Firefox: -moz- Chrome: -webkit- Opera: -o- MS/IE/Edge: -ms- Each browser have a set of specifications related to any style. This is one of the reasons why browser prefixed are implemented in order to ensure that these browsers support any of the specific 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 prefix 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 Specific & 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 different 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 conflicts 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, Modifier): Block Element Modifier 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 flexible 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 Spacificity (*, 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 benefits of using it is to help you find 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