SlideShare a Scribd company logo
< w e b / F>
CSS architecture
CSS is as important as JavaScript
< w e b / F><web/F>
Why CSS architecture?
It is not as trivial as you think
< w e b / F><web/F>
CSS tragedy
The great tragedy of CSS is that it doesn’t stop your application
if CSS is broken.
And that is why CSS always takes a backseat to JavaScript.
< w e b / F><web/F>
If CSS break
• Breaking of JavaScript may disable use of certain feature.
• But if CSS is broken, then your presentation layer break. This is big
compromise on User experience.
• Bad UX is definitely a game loser.
< w e b / F><web/F>
Why do we need CSS architecture?
• Just one word - maintainability
• Enterpriseapplication developmentis a world of
• RRC – Rapid requirement change
• Scale – Huge scale
< w e b / F><web/F>
Idea of architecture
• Set of patterns
• Promoting good practices
< w e b / F><web/F>
Tenets of good architecture
• DRY – Do not repeat Yourself
• Reusable
• Predictable
• Maintainable
< w e b / F><web/F>
Problem with plain CSS
• Repetition cannot be easily avoid
• Reuse is hard
• Future friendly CSS is hard
< w e b / F><web/F>
Days of writing plain CSS are almost over…
< w e b / F><web/F>
CSS tool chain
• CSS pre-processors
• SASS, LESS, Stylus, etc.
• CSS post-processor
< w e b / F><web/F>
SASS vs. LESS
• Which one should you chose?
< w e b / F><web/F>
CSS frameworks
• Foundation
• Bootstrap
• Others
< w e b / F><web/F>
Common CSS problems
Techniques to write better CSS
< w e b / F><web/F>
Problem 1
CSS code structure
How to map it properly with Angular folder structure
< w e b / F><web/F>
< w e b / F><web/F>
Problem 2
Variable naming
Choosing appropriate variable names
< w e b / F><web/F>
Max width example
$max-width: 1440px;
.about-panel {
max-width: $max-width;
}
< w e b / F><web/F>
Max width example
$max-width-1200: 1200px;
$max-width-1440: 1440px;
$max-width-1920: 1920px;
.about-panel {
max-width: $max-width-1440;
}
< w e b / F><web/F>
$max-width-1200: 1200px;
$max-width-1440: 1440px;
$max-width-1920: 1920px;
$max-width-primary: $max-width-1440;
.about-panel {
max-width: $max-width-primary;
}
< w e b / F><web/F>
Problem 3
Color palette design
Standardizing most powerful elements of web
< w e b / F><web/F>
/* Blue color */
$fresh_blue: #2C95DD;
$blue: #2185D0;
$retro_blue: #81A4C6;
/* Black color */
$black: #000000;
$tone_dark_1: #333333;
$tone_dark_2: #606060;
$tone_dark_3: #666666;
/* White color */
$white: #FFFFFF;
$tone_white_0: #F8F8F8;
$tone_white_1: #F0F0F0;
$tone_white_2: #E1E1E1;
$tone_white_3: #CDCDCD;
$tone_white_4: #BABCBE;
$tone_white_1_trans: rgba(225, 225,
225, 0.5);
< w e b / F><web/F>
Name that color
http://chir.ag/projects/name-that-color/
http://www.color-blindness.com/color-name-hue/
< w e b / F><web/F>
// Color palette
$color-alabaster: #F8F8F8;
$color-concrete: #F2F2F2;
$color-gray: #888888;
$color-kelp: #464637;
$color-niagara: #0AAB8A;
$color-pelorous: #3DB0B4;
$color-red-berry: #8C0000;
$color-white: #FFFFFF;
// Site wide colors
$link-color: $color-niagara;
$color-primary: $color-niagara;
< w e b / F><web/F>
Problem 4
Responsive CSS layout
Writing better readable code
< w e b / F><web/F>
Responsive layout approach
Mobile first
.contact-info-section {
margin-top: 2rem;
@media all and (min-width: 768px) {
margin-top: 4rem;
}
}
Desktop first
.contact-info-section {
margin-top: 4rem;
@media all and (max-width: 768px) {
margin-top: 2rem;
}
}
< w e b / F><web/F>
Is it a good media query
.contact-info-section {
margin-top: 2rem;
@media all and (min-width: 768px) {
margin-top: 4rem;
}
}
< w e b / F><web/F>
Ideal media queries
.contact-info-section {
margin-top: 2rem;
@media #{$medium-up} {
margin-top: 4rem;
}
}
< w e b / F><web/F>
CSS now has feature detection
@supports (display: flex) {
div { display: flex; }
}
@supports not (display: flex) {
div { float: left; } /* alternative styles */
}
< w e b / F><web/F>
Problem 5
Future friendly CSS
Developers should not worry
< w e b / F><web/F>
How cross browser CSS is written
.about-section {
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works)
*/
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display: flex;
}
< w e b / F><web/F>
Let’s write mixin for that
@mixin display-flex() {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.about-section { @include display-flex; }
< w e b / F><web/F>
Idea is to use CSS post-processor
Sass
Stylus
CSS
preprocessors
Less
Post CSS
(autoprefixer)
CSS CSS
CSS uglify
(minify, concat)
Bundled
CSS
Build script (Grunt, Gulp, NPM, etc.)
< w e b / F><web/F>
Problem 6
Being nicer to reusability
Carefully choosing selectors
< w e b / F><web/F>
Being specific
/* Grenade */
#main-nav ul li ul { }
/* Sniper Rifle */
.subnav { }
< w e b / F><web/F>
Better namespacing
/* High risk of style cross-contamination */
.widget { }
.widget .title { }
/* Low risk of style cross-contamination */
.widget { }
.widget-title { }
< w e b / F><web/F>
Component extension
/* Bad */
.widget { }
#sidebar .widget { }
/* Good */
.widget { }
.widget-sidebar { }
< w e b / F><web/F>
CSS architecture
Writing a CSS with same concern as JS is a key to better and efficient
design. Don’t ignore it.
< w e b / F><web/F>
By
Harshal Patil
@mistyharsh

More Related Content

PDF
I - Front-end Spectrum
PDF
II - Angular.js app structure
PDF
2015 - Introduction to building enterprise web applications using Angular.js
PDF
III - Better angularjs
PPTX
Word press development for non developers
PDF
WordCamp Sheffield 2014 Theme Workflow Presentation
PDF
Build WordPress themes like a heavyweight - WordCamp Lancaster 2013
PDF
WordCamp Bournemouth 2014 - Designing with data in WordPress
I - Front-end Spectrum
II - Angular.js app structure
2015 - Introduction to building enterprise web applications using Angular.js
III - Better angularjs
Word press development for non developers
WordCamp Sheffield 2014 Theme Workflow Presentation
Build WordPress themes like a heavyweight - WordCamp Lancaster 2013
WordCamp Bournemouth 2014 - Designing with data in WordPress

What's hot (20)

PPTX
The WordPress REST API as a Springboard for Website Greatness
PDF
Rapid WordPress theme development
PDF
Best Friend || Worst Enemy: WordPress Multisite
PDF
jQuery Chicago 2014 - Next-generation JavaScript Testing
KEY
Flash And Dom
PDF
PPTX
Blazor Full-Stack
PDF
A 20 minute introduction to AngularJS for XPage developers
PPTX
Optimizing Your Site for Holiday Traffic
PDF
Front-End Frameworks: a quick overview
PDF
CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
PDF
State of jQuery June 2013 - Portland
PDF
Drawing the Line with Browser Compatibility
PDF
Debugging WordPress Performance using EasyEngine
PPTX
EscConf - Deep Dive Frontend Optimization
PPTX
Mobious(ES6 Isomorphic Flux/ReactJS Boilerplate)
PDF
Building the next generation of themes with WP Rig 2.0
PPTX
Razor into the Razor'verse
PDF
How to Build Custom WordPress Blocks
KEY
Thats Not Flash?
The WordPress REST API as a Springboard for Website Greatness
Rapid WordPress theme development
Best Friend || Worst Enemy: WordPress Multisite
jQuery Chicago 2014 - Next-generation JavaScript Testing
Flash And Dom
Blazor Full-Stack
A 20 minute introduction to AngularJS for XPage developers
Optimizing Your Site for Holiday Traffic
Front-End Frameworks: a quick overview
CSS Grid Changes Everything - Keynote at WebCamp Zagreb 2017
State of jQuery June 2013 - Portland
Drawing the Line with Browser Compatibility
Debugging WordPress Performance using EasyEngine
EscConf - Deep Dive Frontend Optimization
Mobious(ES6 Isomorphic Flux/ReactJS Boilerplate)
Building the next generation of themes with WP Rig 2.0
Razor into the Razor'verse
How to Build Custom WordPress Blocks
Thats Not Flash?
Ad

Similar to IV - CSS architecture (20)

PDF
CSS vs. JavaScript - Trust vs. Control
PDF
Simply Responsive CSS3
PDF
CSS3: Ripe and Ready to Respond
PDF
CSS3 - is everything we used to do wrong?
PDF
CSS Best Practices
PDF
Intro to CSS3
PDF
Dangerous CSS
PDF
CSS3: Ripe and Ready
PDF
CSS3: Ripe and Ready to Respond
PDF
CSS Frameworks
PDF
Accelerated Stylesheets
PDF
CSS: a rapidly changing world
PPT
Web design-workflow
PDF
Create a landing page
KEY
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
PPTX
Css for Development
KEY
Getting started with CSS frameworks using Zurb foundation
PDF
Modular HTML & CSS Turbo Workshop
PDF
Knowing it all
PPTX
Css methods architecture
CSS vs. JavaScript - Trust vs. Control
Simply Responsive CSS3
CSS3: Ripe and Ready to Respond
CSS3 - is everything we used to do wrong?
CSS Best Practices
Intro to CSS3
Dangerous CSS
CSS3: Ripe and Ready
CSS3: Ripe and Ready to Respond
CSS Frameworks
Accelerated Stylesheets
CSS: a rapidly changing world
Web design-workflow
Create a landing page
Bringing sexy back to CSS: SASS/SCSS, LESS and Compass
Css for Development
Getting started with CSS frameworks using Zurb foundation
Modular HTML & CSS Turbo Workshop
Knowing it all
Css methods architecture
Ad

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Electronic commerce courselecture one. Pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
Network Security Unit 5.pdf for BCA BBA.
The Rise and Fall of 3GPP – Time for a Sabbatical?
Dropbox Q2 2025 Financial Results & Investor Presentation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Advanced methodologies resolving dimensionality complications for autism neur...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Review of recent advances in non-invasive hemoglobin estimation
Electronic commerce courselecture one. Pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
sap open course for s4hana steps from ECC to s4
MYSQL Presentation for SQL database connectivity
Unlocking AI with Model Context Protocol (MCP)

IV - CSS architecture

  • 1. < w e b / F> CSS architecture CSS is as important as JavaScript
  • 2. < w e b / F><web/F> Why CSS architecture? It is not as trivial as you think
  • 3. < w e b / F><web/F> CSS tragedy The great tragedy of CSS is that it doesn’t stop your application if CSS is broken. And that is why CSS always takes a backseat to JavaScript.
  • 4. < w e b / F><web/F> If CSS break • Breaking of JavaScript may disable use of certain feature. • But if CSS is broken, then your presentation layer break. This is big compromise on User experience. • Bad UX is definitely a game loser.
  • 5. < w e b / F><web/F> Why do we need CSS architecture? • Just one word - maintainability • Enterpriseapplication developmentis a world of • RRC – Rapid requirement change • Scale – Huge scale
  • 6. < w e b / F><web/F> Idea of architecture • Set of patterns • Promoting good practices
  • 7. < w e b / F><web/F> Tenets of good architecture • DRY – Do not repeat Yourself • Reusable • Predictable • Maintainable
  • 8. < w e b / F><web/F> Problem with plain CSS • Repetition cannot be easily avoid • Reuse is hard • Future friendly CSS is hard
  • 9. < w e b / F><web/F> Days of writing plain CSS are almost over…
  • 10. < w e b / F><web/F> CSS tool chain • CSS pre-processors • SASS, LESS, Stylus, etc. • CSS post-processor
  • 11. < w e b / F><web/F> SASS vs. LESS • Which one should you chose?
  • 12. < w e b / F><web/F> CSS frameworks • Foundation • Bootstrap • Others
  • 13. < w e b / F><web/F> Common CSS problems Techniques to write better CSS
  • 14. < w e b / F><web/F> Problem 1 CSS code structure How to map it properly with Angular folder structure
  • 15. < w e b / F><web/F>
  • 16. < w e b / F><web/F> Problem 2 Variable naming Choosing appropriate variable names
  • 17. < w e b / F><web/F> Max width example $max-width: 1440px; .about-panel { max-width: $max-width; }
  • 18. < w e b / F><web/F> Max width example $max-width-1200: 1200px; $max-width-1440: 1440px; $max-width-1920: 1920px; .about-panel { max-width: $max-width-1440; }
  • 19. < w e b / F><web/F> $max-width-1200: 1200px; $max-width-1440: 1440px; $max-width-1920: 1920px; $max-width-primary: $max-width-1440; .about-panel { max-width: $max-width-primary; }
  • 20. < w e b / F><web/F> Problem 3 Color palette design Standardizing most powerful elements of web
  • 21. < w e b / F><web/F> /* Blue color */ $fresh_blue: #2C95DD; $blue: #2185D0; $retro_blue: #81A4C6; /* Black color */ $black: #000000; $tone_dark_1: #333333; $tone_dark_2: #606060; $tone_dark_3: #666666; /* White color */ $white: #FFFFFF; $tone_white_0: #F8F8F8; $tone_white_1: #F0F0F0; $tone_white_2: #E1E1E1; $tone_white_3: #CDCDCD; $tone_white_4: #BABCBE; $tone_white_1_trans: rgba(225, 225, 225, 0.5);
  • 22. < w e b / F><web/F> Name that color http://chir.ag/projects/name-that-color/ http://www.color-blindness.com/color-name-hue/
  • 23. < w e b / F><web/F> // Color palette $color-alabaster: #F8F8F8; $color-concrete: #F2F2F2; $color-gray: #888888; $color-kelp: #464637; $color-niagara: #0AAB8A; $color-pelorous: #3DB0B4; $color-red-berry: #8C0000; $color-white: #FFFFFF; // Site wide colors $link-color: $color-niagara; $color-primary: $color-niagara;
  • 24. < w e b / F><web/F> Problem 4 Responsive CSS layout Writing better readable code
  • 25. < w e b / F><web/F> Responsive layout approach Mobile first .contact-info-section { margin-top: 2rem; @media all and (min-width: 768px) { margin-top: 4rem; } } Desktop first .contact-info-section { margin-top: 4rem; @media all and (max-width: 768px) { margin-top: 2rem; } }
  • 26. < w e b / F><web/F> Is it a good media query .contact-info-section { margin-top: 2rem; @media all and (min-width: 768px) { margin-top: 4rem; } }
  • 27. < w e b / F><web/F> Ideal media queries .contact-info-section { margin-top: 2rem; @media #{$medium-up} { margin-top: 4rem; } }
  • 28. < w e b / F><web/F> CSS now has feature detection @supports (display: flex) { div { display: flex; } } @supports not (display: flex) { div { float: left; } /* alternative styles */ }
  • 29. < w e b / F><web/F> Problem 5 Future friendly CSS Developers should not worry
  • 30. < w e b / F><web/F> How cross browser CSS is written .about-section { display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */ display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */ display: -ms-flexbox; /* TWEENER - IE 10 */ display: -webkit-flex; /* NEW - Chrome */ display: flex; }
  • 31. < w e b / F><web/F> Let’s write mixin for that @mixin display-flex() { display: -webkit-box; display: -moz-box; display: -ms-flexbox; display: -webkit-flex; display: flex; } .about-section { @include display-flex; }
  • 32. < w e b / F><web/F> Idea is to use CSS post-processor Sass Stylus CSS preprocessors Less Post CSS (autoprefixer) CSS CSS CSS uglify (minify, concat) Bundled CSS Build script (Grunt, Gulp, NPM, etc.)
  • 33. < w e b / F><web/F> Problem 6 Being nicer to reusability Carefully choosing selectors
  • 34. < w e b / F><web/F> Being specific /* Grenade */ #main-nav ul li ul { } /* Sniper Rifle */ .subnav { }
  • 35. < w e b / F><web/F> Better namespacing /* High risk of style cross-contamination */ .widget { } .widget .title { } /* Low risk of style cross-contamination */ .widget { } .widget-title { }
  • 36. < w e b / F><web/F> Component extension /* Bad */ .widget { } #sidebar .widget { } /* Good */ .widget { } .widget-sidebar { }
  • 37. < w e b / F><web/F> CSS architecture Writing a CSS with same concern as JS is a key to better and efficient design. Don’t ignore it.
  • 38. < w e b / F><web/F> By Harshal Patil @mistyharsh