news.volyx.in

CSS's !important was added because of laws about font size for some text (twitter.com)

489 points by mmastrac · 1638 days ago · 330 comments on HN

Article summary

CSS co-designer Steven Pemberton stated that the !important keyword was added to CSS due to US laws requiring certain text to be in a given font size. He claimed that anything else is probably misuse and a sign of not understanding the cascade properly. The commenters discussed the practicality and usefulness of !important in real-world front-end development. They shared their experiences and opinions on when and how to use !important, with some arguing it is necessary and others claiming it is a sign of poor CSS structure.

Main themes

  • CSS !important keyword
  • Front-end development challenges
  • CSS structure and best practices
  • Practicality vs. theoretical correctness
  • Legacy code and third-party code issues
  • CSS specificity and override techniques

What commenters say

  • The use of !important is often necessary in real-world front-end development due to the complexity of CSS and the need to override existing styles.
  • The cascade is a flawed design that falls apart in practice, making !important a necessary tool for many developers.
  • Proper use of CSS requires discipline and structure, and !important is often a sign of poor CSS design.
  • The criticism of !important is overstated and based on outdated wisdom, rather than actual best practices.
  • Using !important can be a practical solution when working with large and complex CSS codebases.
  • Increasing specificity is a better approach than using !important, as it allows for more control and flexibility in CSS.
  • In some cases, using !important is the only way to override existing styles, especially when working with third-party code or legacy systems.