Asked 6 years ago
13 Jan 2018
Views 1093
jessica

jessica posted

what is use of !important in css ?

what is use of !important in css ?
web-api

web-api
answered Apr 25 '23 00:00

The !important keyword in CSS is used to override the cascading order of styles that are applied to HTML elements. When a style is marked with ! important , it takes precedence over other styles that are defined for the same element.

While !important can be useful in certain situations, it should generally be avoided as it can make it difficult to maintain and update the styles of a website or application over time. It's important to note that using !important can result in unexpected behavior if not used correctly.

Here's an example of how !important can be used in CSS:



p {
  color: red !important;
}

/* This style will be overridden by the above style */
p {
  color: blue;
}

In the above example, the color property of all p elements will be set to red, regardless of any other styles that may try to set the color property to a different value. This is because the ! important keyword has been used to give the first style priority over any other styles that may be defined.

It's important to use ! important sparingly and only when necessary, as overuse of the keyword can make it difficult to maintain and update the styles of a website or application
Post Answer