Kevin Powell - CommunityKP-C
Kevin Powell - Communityโ€ข8mo agoโ€ข
8 replies
Pedro Garcรญa

CSS ๐Ÿ‘‰๐Ÿผ What is the specificity of HTML elements with the style attribute?

Hello! I'm deep diving into how specificity is added to CSS selectors, and I became curious about this.


Given the following code:
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Important and style attribute</title>
  <style>
    .red {
      background-color: red !important;
    }
  </style>
</head>

<body>
  <div style="background-color: blue !important" class="red">I'm important!</div>
</body>

</html>


The background-color of the <div> will be blue. But what is the criteria for this? Do HTML elements with the
style
attribute have a special criteria for them? Because when it comes to specificity, the class is more specific than the element (although it seems like that's not the rule that applies here) ๐Ÿค”
Was this page helpful?