Which selector has high priority in CSS?

    In css selectors  ID and CLASS two selectors
    which selector either id or class can take the highest priority in Css style?

    Baby Asked on April 11, 2016 in HTML and CSS.
    Add Comment
  • 1 Answer(s)

      Q: Which selector has high priority in CSS?
      CSS selectors are used to “find” (or select) HTML elements based on their element name, id, class, attribute, and more.

      css selectors are 1.ID
      2.class
      1.The id selector uses the id attribute of an HTML element to select a specific element.

      ID’s are unique

      *Each element can have only one ID
      *Each page can have only one element with that ID

      2.Class selectors are used to apply style to multiple HTML identified with the same class.

      Classes are NOT unique

      *You can use the same class on multiple elements.
      *You can use multiple classes on the same element.

      lets see the which selector is high priority

      Priority 1 : ID ID
      Priority 2 : ID Class
      Priority 3 : ID Element
      Priority 4 : ID
      Priority 4 : Class class
      Priority 6 : Class Element
      Priority 7 : Class
      Priority 8 : Element

      <!DOC-TYPE html>
      <html>
      <head>
      <title>selectors high priority</title>
      <style>

      #abc #def {
      color:red;
      }
      #abc .a {
      color:blue;
      }

      #abc a {
      color:black;
      }
      #abc {
      color:red;
      }
      .abc.def{
      color:black;
      }
      .abc a {
      color:white;
      }
      .abc {
      color:green;
      }
      p {
      color:pink;
      }

      </style>
      </head>

      <body>

      <div id=”abc” <a href=”http://www.w3schools.com”>Visit W3Schools.com!</a></p>
      <p>w3schools</p>

      </div>
      </body>
      </html>

      Baby Answered on April 11, 2016.
      Add Comment

      Your Answer

      By posting your answer, you agree to the privacy policy and terms of service.