! Important attribute in CSS


So many time in interview if we will ask this question with developers. They don’t know “What is Important attribute in CSS” . Here is the answer:

If we have to avoid the override functionality of parent css class, then we can declare as ! important in css. But it is not a good practice to use it in all the scenario . It will be very difficult in debugging process. If it is possible, we have to avoid this features while using in application.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
        div {
            background-color: green !important ;

          <b>This is the sample code of Important in CSS</b>
 <div style="background-color:silver; height:100px; width:500px;">
<p>This is the text in Div</p>


In the above code we have defined all div color should be green. But if we will not used important then developer can override that color with other color using inline css. So if we have to avoid the override the css class we can use important in global css class.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.