Usage of CSS !important rule

CSSWeb DevelopmentFront End Technology

The !important rule provides a way to make your CSS cascade. It also includes the rules that are to be applied always. A rule having a !important property will always be applied, no matter where that rule appears in the CSS document.

For example, in the following style sheet, the paragraph text will be black, even though the first style property applied is red −

<style>
   <!--
   p {
      color: #ff0000;
   }
   p {
      color: #000000;
   }
   -->
</style>

If you want to make sure that a property always applied, you would add the !important property to the tag. Therefore, to make the paragraph text always red, you should write it as follows −

Example

Live Demo

<html>
   <head>
      <style>
         p {
            color: #ff0000 !important;
         }
         p {
            color: #000000;
         }
      </style>
   </head>
   <body>
      <p>Tutorialspoint.com</p>
   </body>
</html>
raja
Published on 27-Apr-2018 06:18:12
Advertisements