SlideShare a Scribd company logo
1 of 23
Download to read offline
6 STEPS TO MAKE YOUR CSS
CODE MORE MAINTAINABLE
FRONT-END DEVELOPER
MARTA
SZTYBOR
CSS is a fairly simple language to learn on a basic level and to kick off with the coding.
But when your stylesheets start to grow, it becomes more and more difficult to untangle
messed up classes.
Here I collected a couple of tips to help you write more manageable
code. They’ll be useful no matter if you’re working on a project’s
styles on your own or in a team.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
MODULARISE
YOUR STYLES
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
Begin treating your UI
as a set of repeatable
modules.
For most webpages it’s
possible to break up the
layout for smaller components,
eg. header with navigation,
footer, article, or even the
smallest building blocks, eg.
buttons and links.
Preprocessors give you the
power to write stylesheets
separately, and then @import
them into the main file.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
MODULARISE YOUR STYLES
DECIDE
ON A NAMING CONVENTION
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
Naming things is hard I’d say, especially if you try to name CSS classes.
Your first thought could be “Let’s name things semantically!”. Yeah, it’s perfectly right! When
the graphic designer changes colours, you don’t want to grep HTML files to change .blue-box
to .green-box (to say the least, there could also be a hundred classes named that way). So, you
decide to choose to name things like .nav-main instead of .large-emerald-shiny-tabs.
But don’t hold on too tightly, the main point is to take the most sensible
approach about naming classes as possible – all of the selector names
don’t have to be semantic. Just follow a coherent convention and don’t
use names describing an element’s appearance.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
DECIDE ON A NAMING CONVENTION
DEAL
WITH SPECIFICITY
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
In general, try to stick to this simple rule of thumb: always try
to use the least specific selectors as possible.
Very specific selectors, like
are hard to override.
In any case, when you have to code a similar element, but with slightly different
styles, you would write a more specific selector, or even be tempted to use
!important. This leads straight to hard-to-maintain code.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
DEAL WITH SPECIFICITY
I would recommend using explicit selectors for an element, like classes:
It looks better, right? You should also avoid using IDs, because they are almost
as specific as inline styles. They also have another drawback: they aren’t
reusable, and this is something we really don’t want to have in our modular CSS.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
DEAL WITH SPECIFICITY
USE PREPROCESSORS
THE RIGHT WAY
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
Preprocessors can really be a double-edged sword. They cannot
guarantee you a clean, well-maintainable code if you don’t use
their features properly.
You should avoid nesting CSS rules, unless it’s really necessary. This is probably
the most common mistake made by beginners. Follow the inception rule:
Don’t go more than four levels deep.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
USE PREPROCESSORS THE RIGHT WAY
Consider following HTML example:
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
USE PREPROCESSORS THE RIGHT WAY
It’s tempting to recreate this HTML structure in styles and write in SCSS:
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
USE PREPROCESSORS THE RIGHT WAY
It then compiles to:
If you needed a similar menu in another page, but with just a little tweaked
color of the link, you’d have to override the last selector, and probably end up
with this:
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
USE PREPROCESSORS THE RIGHT WAY
Not even this creates overly qualified selectors and causes
problems with specificity. With tightly coupled HTML, it be-
comes hard to maintain. When overused, it may cause per-
formance problems and cause your stylesheets to grow in an
uncontrolled manner.
Overly nested rules are also less readable.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
USE PREPROCESSORS THE RIGHT WAY
AVOID
UNDOING STYLES
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
CSS is about inheritance, so why undo values declared in
another selector?
Let’s have styles for headings:
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
AVOID UNDOING STYLES
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
If styles are being resetted in
.header-no-border
class, why declare them for base class
.heading? This would be a simpler and more maintainable way:
AVOID UNDOING STYLES
DOCUMENT YOUR CODE
AND CREATE A STYLE GUIDE
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
CSS is a declarative language, so if you are using meaningful class names
documenting code can seem unnecessary. But thinking about the future and
other people who are or will be involved in your project, comments are an
invaluable thing.
It’s worth to create your own or choose existing code
guidelines, which include naming conventions, methodology
used, commenting style and file structure. This will benefit all
the people who ever touch the code.
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
DOCUMENT YOUR CODE AND CREATE A STYLE GUIDE
This presentation just scratches the surface. If you are interested in this topic, I
can recommend you some excellent resources in the web, which cover the issues
of modular CSS, code maintainability and various methodologies:
•	 Nicolle Sullivan’s Object Oriented CSS (OOCSS)
•	 Jonathan Snook’s Scalable and Modular Architecture for CSS
•	 Mark D. Otto’s code guide
•	 Harry Roberts’ CSS Guidelines
•	 Creating style guides on A List Apart
6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
FURTHER READING
THANK YOU FOR READING
FRONT-END DEVELOPER
MARTA
SZTYBOR

More Related Content

What's hot

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 CSSSanjoy Kr. Paul
 
Introduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersIntroduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersMelvin John
 
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
 
How to use CSS3 in WordPress - Sacramento
How to use CSS3 in WordPress - SacramentoHow to use CSS3 in WordPress - Sacramento
How to use CSS3 in WordPress - SacramentoSuzette Franck
 
Intro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersIntro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersSuzette Franck
 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPressSuzette Franck
 
Front End Best Practices
Front End Best PracticesFront End Best Practices
Front End Best PracticesHolger Bartel
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS WorkshopTim Hettler
 
Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)Thinkful
 
Organize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksOrganize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksAndolasoft Inc
 
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 IDsSteve Kinney
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to BootstrapRon Reiter
 
Arunan Skanthan - Roll Your own Style Guide
Arunan Skanthan - Roll Your own Style GuideArunan Skanthan - Roll Your own Style Guide
Arunan Skanthan - Roll Your own Style GuideWeb Directions
 
Design for Developers: Introduction to Bootstrap 3
Design for Developers: Introduction to Bootstrap 3Design for Developers: Introduction to Bootstrap 3
Design for Developers: Introduction to Bootstrap 3John Bertucci
 
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 #PCTO15Andy McIlwain
 

What's hot (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
 
Introduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for DevelopersIntroduction to Bootstrap: Design for Developers
Introduction to Bootstrap: Design for Developers
 
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
 
How to use CSS3 in WordPress - Sacramento
How to use CSS3 in WordPress - SacramentoHow to use CSS3 in WordPress - Sacramento
How to use CSS3 in WordPress - Sacramento
 
Intro to Sass for WordPress Developers
Intro to Sass for WordPress DevelopersIntro to Sass for WordPress Developers
Intro to Sass for WordPress Developers
 
How to use CSS3 in WordPress
How to use CSS3 in WordPressHow to use CSS3 in WordPress
How to use CSS3 in WordPress
 
Css home
Css   homeCss   home
Css home
 
Front End Best Practices
Front End Best PracticesFront End Best Practices
Front End Best Practices
 
SMACSS Workshop
SMACSS WorkshopSMACSS Workshop
SMACSS Workshop
 
Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)Responsive Web Design (April 18th, Los Angeles)
Responsive Web Design (April 18th, Los Angeles)
 
Lecture2 CSS1
Lecture2  CSS1Lecture2  CSS1
Lecture2 CSS1
 
Organize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS TricksOrganize Your Website With Advanced CSS Tricks
Organize Your Website With Advanced CSS Tricks
 
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
 
Css border examples
Css border examplesCss border examples
Css border examples
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
Arunan Skanthan - Roll Your own Style Guide
Arunan Skanthan - Roll Your own Style GuideArunan Skanthan - Roll Your own Style Guide
Arunan Skanthan - Roll Your own Style Guide
 
Introduction to Bootstrap
Introduction to BootstrapIntroduction to Bootstrap
Introduction to Bootstrap
 
PSD to Theme: The SMACSS Way
PSD to Theme: The SMACSS WayPSD to Theme: The SMACSS Way
PSD to Theme: The SMACSS Way
 
Design for Developers: Introduction to Bootstrap 3
Design for Developers: Introduction to Bootstrap 3Design for Developers: Introduction to Bootstrap 3
Design for Developers: Introduction to Bootstrap 3
 
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
 

Viewers also liked

Data dictionary
Data dictionaryData dictionary
Data dictionaryShaikh Uves
 
Data Dictionary
Data DictionaryData Dictionary
Data DictionaryVishal Anand
 
Object Oriented CSS
Object Oriented CSSObject Oriented CSS
Object Oriented CSSNicole Sullivan
 
From Scratch to Launch #2 - Design phase
From Scratch to Launch #2 - Design phaseFrom Scratch to Launch #2 - Design phase
From Scratch to Launch #2 - Design phaseStacy Kvernmo
 
The benefits of BEM CSS
The benefits of BEM CSSThe benefits of BEM CSS
The benefits of BEM CSSBob Donderwinkel
 
Systems Analyst and Design - Data Dictionary
Systems Analyst and Design -  Data DictionarySystems Analyst and Design -  Data Dictionary
Systems Analyst and Design - Data DictionaryKimberly Coquilla
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery EssentialsMarc Grabanski
 
Atomic design
Atomic designAtomic design
Atomic designBrad Frost
 
The Great State of Design with CSS Grid Layout and Friends
The Great State of Design with CSS Grid Layout and FriendsThe Great State of Design with CSS Grid Layout and Friends
The Great State of Design with CSS Grid Layout and FriendsStacy Kvernmo
 

Viewers also liked (11)

Data dictionary
Data dictionaryData dictionary
Data dictionary
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Data dictionary
Data dictionaryData dictionary
Data dictionary
 
Object Oriented CSS
Object Oriented CSSObject Oriented CSS
Object Oriented CSS
 
From Scratch to Launch #2 - Design phase
From Scratch to Launch #2 - Design phaseFrom Scratch to Launch #2 - Design phase
From Scratch to Launch #2 - Design phase
 
The benefits of BEM CSS
The benefits of BEM CSSThe benefits of BEM CSS
The benefits of BEM CSS
 
Systems Analyst and Design - Data Dictionary
Systems Analyst and Design -  Data DictionarySystems Analyst and Design -  Data Dictionary
Systems Analyst and Design - Data Dictionary
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Data dictionary
Data dictionaryData dictionary
Data dictionary
 
Atomic design
Atomic designAtomic design
Atomic design
 
The Great State of Design with CSS Grid Layout and Friends
The Great State of Design with CSS Grid Layout and FriendsThe Great State of Design with CSS Grid Layout and Friends
The Great State of Design with CSS Grid Layout and Friends
 

Similar to 6 Steps to Make Your CSS Code More Maintainable

The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbookjackchenvlo
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to cssnikhilsh66131
 
SCSS Implementation
SCSS ImplementationSCSS Implementation
SCSS ImplementationAmey Parab
 
Css masterclass book
Css masterclass bookCss masterclass book
Css masterclass bookPhoenix
 
Design and CSS
Design and CSSDesign and CSS
Design and CSSnolly00
 
Sass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by ShafeeqSass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by ShafeeqDignitasDigital1
 
CSS Best Practices
CSS Best PracticesCSS Best Practices
CSS Best Practicesnolly00
 
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
 
Lesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ayLesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ayCodecademy Ren
 
Architecting with Style
Architecting with StyleArchitecting with Style
Architecting with StyleTimothy Knight
 
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 cssNeil Perlin
 
SASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome StylesheetSASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome StylesheetNeha Sharma
 
An Introduction to CSS Frameworks
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS FrameworksAdrian Westlake
 
The World of Stylesheet Languages
The World of Stylesheet LanguagesThe World of Stylesheet Languages
The World of Stylesheet LanguagesAndrea Tino
 
Object oriented css. Graeme Blackwood
Object oriented css. Graeme BlackwoodObject oriented css. Graeme Blackwood
Object oriented css. Graeme BlackwoodPVasili
 
Object oriented css graeme blackwood
Object oriented css graeme blackwoodObject oriented css graeme blackwood
Object oriented css graeme blackwooddrupalconf
 
Styling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projectsStyling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projectsAppsilon Data Science
 
CSS_GUIDE_Intro
CSS_GUIDE_IntroCSS_GUIDE_Intro
CSS_GUIDE_Introtutorialsruby
 
CSS_GUIDE_Intro
CSS_GUIDE_IntroCSS_GUIDE_Intro
CSS_GUIDE_Introtutorialsruby
 

Similar to 6 Steps to Make Your CSS Code More Maintainable (20)

The CSS Handbook
The CSS HandbookThe CSS Handbook
The CSS Handbook
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
SCSS Implementation
SCSS ImplementationSCSS Implementation
SCSS Implementation
 
Css masterclass book
Css masterclass bookCss masterclass book
Css masterclass book
 
Design and CSS
Design and CSSDesign and CSS
Design and CSS
 
Sass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by ShafeeqSass:-Syntactically Awesome Stylesheet by Shafeeq
Sass:-Syntactically Awesome Stylesheet by Shafeeq
 
CSS Best Practices
CSS Best PracticesCSS Best Practices
CSS Best Practices
 
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!
 
Lesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ayLesson 110 24 aug13-1400-ay
Lesson 110 24 aug13-1400-ay
 
Architecting with Style
Architecting with StyleArchitecting with Style
Architecting with Style
 
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
 
SASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome StylesheetSASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome Stylesheet
 
An Introduction to CSS Frameworks
An Introduction to CSS FrameworksAn Introduction to CSS Frameworks
An Introduction to CSS Frameworks
 
The World of Stylesheet Languages
The World of Stylesheet LanguagesThe World of Stylesheet Languages
The World of Stylesheet Languages
 
Object oriented css. Graeme Blackwood
Object oriented css. Graeme BlackwoodObject oriented css. Graeme Blackwood
Object oriented css. Graeme Blackwood
 
Object oriented css graeme blackwood
Object oriented css graeme blackwoodObject oriented css graeme blackwood
Object oriented css graeme blackwood
 
Styling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projectsStyling your projects! leveraging css and r sass in r projects
Styling your projects! leveraging css and r sass in r projects
 
Your CSS is Awesome
Your CSS is AwesomeYour CSS is Awesome
Your CSS is Awesome
 
CSS_GUIDE_Intro
CSS_GUIDE_IntroCSS_GUIDE_Intro
CSS_GUIDE_Intro
 
CSS_GUIDE_Intro
CSS_GUIDE_IntroCSS_GUIDE_Intro
CSS_GUIDE_Intro
 

Recently uploaded

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsYoss Cohen
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Recently uploaded (20)

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
Infrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platformsInfrared simulation and processing on Nvidia platforms
Infrared simulation and processing on Nvidia platforms
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

6 Steps to Make Your CSS Code More Maintainable

  • 1.
  • 2. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE FRONT-END DEVELOPER MARTA SZTYBOR
  • 3. CSS is a fairly simple language to learn on a basic level and to kick off with the coding. But when your stylesheets start to grow, it becomes more and more difficult to untangle messed up classes. Here I collected a couple of tips to help you write more manageable code. They’ll be useful no matter if you’re working on a project’s styles on your own or in a team. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
  • 4. MODULARISE YOUR STYLES 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
  • 5. Begin treating your UI as a set of repeatable modules. For most webpages it’s possible to break up the layout for smaller components, eg. header with navigation, footer, article, or even the smallest building blocks, eg. buttons and links. Preprocessors give you the power to write stylesheets separately, and then @import them into the main file. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE MODULARISE YOUR STYLES
  • 6. DECIDE ON A NAMING CONVENTION 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
  • 7. Naming things is hard I’d say, especially if you try to name CSS classes. Your first thought could be “Let’s name things semantically!”. Yeah, it’s perfectly right! When the graphic designer changes colours, you don’t want to grep HTML files to change .blue-box to .green-box (to say the least, there could also be a hundred classes named that way). So, you decide to choose to name things like .nav-main instead of .large-emerald-shiny-tabs. But don’t hold on too tightly, the main point is to take the most sensible approach about naming classes as possible – all of the selector names don’t have to be semantic. Just follow a coherent convention and don’t use names describing an element’s appearance. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE DECIDE ON A NAMING CONVENTION
  • 8. DEAL WITH SPECIFICITY 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
  • 9. In general, try to stick to this simple rule of thumb: always try to use the least specific selectors as possible. Very specific selectors, like are hard to override. In any case, when you have to code a similar element, but with slightly different styles, you would write a more specific selector, or even be tempted to use !important. This leads straight to hard-to-maintain code. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE DEAL WITH SPECIFICITY
  • 10. I would recommend using explicit selectors for an element, like classes: It looks better, right? You should also avoid using IDs, because they are almost as specific as inline styles. They also have another drawback: they aren’t reusable, and this is something we really don’t want to have in our modular CSS. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE DEAL WITH SPECIFICITY
  • 11. USE PREPROCESSORS THE RIGHT WAY 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
  • 12. Preprocessors can really be a double-edged sword. They cannot guarantee you a clean, well-maintainable code if you don’t use their features properly. You should avoid nesting CSS rules, unless it’s really necessary. This is probably the most common mistake made by beginners. Follow the inception rule: Don’t go more than four levels deep. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE USE PREPROCESSORS THE RIGHT WAY
  • 13. Consider following HTML example: 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE USE PREPROCESSORS THE RIGHT WAY
  • 14. It’s tempting to recreate this HTML structure in styles and write in SCSS: 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE USE PREPROCESSORS THE RIGHT WAY
  • 15. It then compiles to: If you needed a similar menu in another page, but with just a little tweaked color of the link, you’d have to override the last selector, and probably end up with this: 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE USE PREPROCESSORS THE RIGHT WAY
  • 16. Not even this creates overly qualified selectors and causes problems with specificity. With tightly coupled HTML, it be- comes hard to maintain. When overused, it may cause per- formance problems and cause your stylesheets to grow in an uncontrolled manner. Overly nested rules are also less readable. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE USE PREPROCESSORS THE RIGHT WAY
  • 17. AVOID UNDOING STYLES 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
  • 18. CSS is about inheritance, so why undo values declared in another selector? Let’s have styles for headings: 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE AVOID UNDOING STYLES
  • 19. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE If styles are being resetted in .header-no-border class, why declare them for base class .heading? This would be a simpler and more maintainable way: AVOID UNDOING STYLES
  • 20. DOCUMENT YOUR CODE AND CREATE A STYLE GUIDE 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE
  • 21. CSS is a declarative language, so if you are using meaningful class names documenting code can seem unnecessary. But thinking about the future and other people who are or will be involved in your project, comments are an invaluable thing. It’s worth to create your own or choose existing code guidelines, which include naming conventions, methodology used, commenting style and file structure. This will benefit all the people who ever touch the code. 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE DOCUMENT YOUR CODE AND CREATE A STYLE GUIDE
  • 22. This presentation just scratches the surface. If you are interested in this topic, I can recommend you some excellent resources in the web, which cover the issues of modular CSS, code maintainability and various methodologies: • Nicolle Sullivan’s Object Oriented CSS (OOCSS) • Jonathan Snook’s Scalable and Modular Architecture for CSS • Mark D. Otto’s code guide • Harry Roberts’ CSS Guidelines • Creating style guides on A List Apart 6 STEPS TO MAKE YOUR CSS CODE MORE MAINTAINABLE FURTHER READING
  • 23. THANK YOU FOR READING FRONT-END DEVELOPER MARTA SZTYBOR