SlideShare a Scribd company logo
When CSS !important
BY: AAMIR SHAHZAD
FRONT END DEVELOPER
HTTP://AAMIRSHAHZAD.NET
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Contents
 History
 Syntax
 What CSS !important does?
 When to use !important
 Cons of !important
 Fun facts about !important
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
History
CSS !important was added in CSS 2.1 (no changes to it in CSS3)
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Syntax
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
What CSS !important does?
An !important declaration provides a way for a web designer or developer to give a CSS value
more weight than it naturally has.
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Sometimes…
WHY CSS NOT WORKING?
Use !important rule (whisper)
OK, now it's working
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
When to use !important…
Never!!!
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
However…
When using external CSS from CDN you can’t change
When using a plugin having CSS you can’t change; like bootstrap CSS
When requirement is a property not to over-ride even by JavaScript
When too much effort is required if you want to avoid it and adding it doesn’t effect much
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Still these can be solved!
When using external CSS from CDN you can’t change
When using a plugin having CSS you can’t change; like bootstrap CSS
Adding CSS from CDN or plugin before your normal CSS file, will allow you to not use !important
except any property having !important in that CSS.
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Cons
Code will not be maintainable
If you have added !important with some generic CSS properties you have to override each time
if you want something different + this class. So never use !important with generic class.
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Cons
!important disrupts the natural flow
Naturally style of second class should apply. But as first class using !important therefore, this will
be overridden by first class. Use different classes to avoid this problem.
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Cons
He/she has to debug and find why his/her applied style is not applying. They have run through
code where and why !important is used. To apply their style every time they have to use
!important with CSS property value otherwise style will not apply.
Painful for other developers
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Cons
One !important means there will be others
Yes this very right once you have started using !important specially with some generic class or
element each time in order to apply new style on an element you have to add !important. Which
a bad practice.
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Fun facts
In IE6 and IE7, if you use a different word in place of !important (like !somedog), the CSS rule will
still be given extra weight, while other browsers will ignore it
If for some particular reason you have to write the same property twice in the same declaration
block, then add !important to the end of the first one, the first one will have more weight in
every browser except IE6 (this works as an IE6-only hack, but doesn’t invalidate your CSS)
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Common symptoms
1. Fatigue
2. Tension
3. Revenge
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
Any Questions or Suggestions ???
7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET

More Related Content

Similar to When css !important is the right choice?

Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
Felipe Lavín
 

Similar to When css !important is the right choice? (20)

The New Renaissance of JavaScript
The New Renaissance of JavaScriptThe New Renaissance of JavaScript
The New Renaissance of JavaScript
 
Test-proof CSS
Test-proof CSSTest-proof CSS
Test-proof CSS
 
MySQL 8.0 Document Store - how to mix NoSQL & SQL in MySQL 8.0
MySQL 8.0 Document Store - how to mix NoSQL & SQL in MySQL 8.0MySQL 8.0 Document Store - how to mix NoSQL & SQL in MySQL 8.0
MySQL 8.0 Document Store - how to mix NoSQL & SQL in MySQL 8.0
 
Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017Front End Development for Back End Developers - vJUG24 2017
Front End Development for Back End Developers - vJUG24 2017
 
ZURB Foundation 5: Clean + Organized
ZURB Foundation 5: Clean + OrganizedZURB Foundation 5: Clean + Organized
ZURB Foundation 5: Clean + Organized
 
Css · bootstrap
Css · bootstrapCss · bootstrap
Css · bootstrap
 
Frontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser renderingFrontend Performance: Illusions & browser rendering
Frontend Performance: Illusions & browser rendering
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015WordPress Meetup - Top 9 September 2015
WordPress Meetup - Top 9 September 2015
 
Even faster web sites presentation 3
Even faster web sites presentation 3Even faster web sites presentation 3
Even faster web sites presentation 3
 
Tailwind CSS - KanpurJS
Tailwind CSS - KanpurJSTailwind CSS - KanpurJS
Tailwind CSS - KanpurJS
 
CSS Best practice
CSS Best practiceCSS Best practice
CSS Best practice
 
Android app development Hybrid approach for beginners
Android app development  Hybrid approach for beginnersAndroid app development  Hybrid approach for beginners
Android app development Hybrid approach for beginners
 
Let There Be Peace On CSS
Let There Be Peace On CSSLet There Be Peace On CSS
Let There Be Peace On CSS
 
Modern Front-End Development
Modern Front-End DevelopmentModern Front-End Development
Modern Front-End Development
 
Efficient, maintainable CSS
Efficient, maintainable CSSEfficient, maintainable CSS
Efficient, maintainable CSS
 
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Solving Complex JavaScript Issues and Leveraging Semantic HTML5Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
 
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com RubyFisl 11 - Dicas de Desenvolvimento Web com Ruby
Fisl 11 - Dicas de Desenvolvimento Web com Ruby
 
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com RubyConsegi 2010 - Dicas de Desenvolvimento Web com Ruby
Consegi 2010 - Dicas de Desenvolvimento Web com Ruby
 
Front End Development for Backend Developers - GIDS 2019
Front End Development for Backend Developers - GIDS 2019Front End Development for Backend Developers - GIDS 2019
Front End Development for Backend Developers - GIDS 2019
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya HalderCustom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
Custom Approval Process: A New Perspective, Pavel Hrbacek & Anindya Halder
 
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
 
The architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdfThe architecture of Generative AI for enterprises.pdf
The architecture of Generative AI for enterprises.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
"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
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
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
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 

When css !important is the right choice?

  • 1. When CSS !important BY: AAMIR SHAHZAD FRONT END DEVELOPER HTTP://AAMIRSHAHZAD.NET 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 2. Contents  History  Syntax  What CSS !important does?  When to use !important  Cons of !important  Fun facts about !important 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 3. History CSS !important was added in CSS 2.1 (no changes to it in CSS3) 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 4. Syntax 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 5. What CSS !important does? An !important declaration provides a way for a web designer or developer to give a CSS value more weight than it naturally has. 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 6. Sometimes… WHY CSS NOT WORKING? Use !important rule (whisper) OK, now it's working 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 7. When to use !important… Never!!! 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 8. However… When using external CSS from CDN you can’t change When using a plugin having CSS you can’t change; like bootstrap CSS When requirement is a property not to over-ride even by JavaScript When too much effort is required if you want to avoid it and adding it doesn’t effect much 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 9. Still these can be solved! When using external CSS from CDN you can’t change When using a plugin having CSS you can’t change; like bootstrap CSS Adding CSS from CDN or plugin before your normal CSS file, will allow you to not use !important except any property having !important in that CSS. 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 10. Cons Code will not be maintainable If you have added !important with some generic CSS properties you have to override each time if you want something different + this class. So never use !important with generic class. 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 11. Cons !important disrupts the natural flow Naturally style of second class should apply. But as first class using !important therefore, this will be overridden by first class. Use different classes to avoid this problem. 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 12. Cons He/she has to debug and find why his/her applied style is not applying. They have run through code where and why !important is used. To apply their style every time they have to use !important with CSS property value otherwise style will not apply. Painful for other developers 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 13. Cons One !important means there will be others Yes this very right once you have started using !important specially with some generic class or element each time in order to apply new style on an element you have to add !important. Which a bad practice. 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 14. Fun facts In IE6 and IE7, if you use a different word in place of !important (like !somedog), the CSS rule will still be given extra weight, while other browsers will ignore it If for some particular reason you have to write the same property twice in the same declaration block, then add !important to the end of the first one, the first one will have more weight in every browser except IE6 (this works as an IE6-only hack, but doesn’t invalidate your CSS) 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 15. Common symptoms 1. Fatigue 2. Tension 3. Revenge 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET
  • 16. Any Questions or Suggestions ??? 7/26/2015 AAMIR SHAHZAD - HTTP://AAMIRSHAHZAD.NET