</>
ValidateHTML

Inline Styles Overriding CSS

Inline styles (the style attribute on HTML elements) have higher specificity than any CSS selector. This means your external CSS rules can't override them, no matter how specific your selector is. The only way to beat an inline style is with !important.

Why It Matters

Inline styles break the cascade, making your CSS unpredictable. When CSS 'doesn't work', inline styles on the element are often the hidden cause. They create a maintenance nightmare where changing styles requires editing HTML instead of CSS.

Code Examples

Bad CSS
<!-- HTML -->
<div style="padding: 20px; background: red;">
  Content
</div>

/* CSS: this will NOT override the inline style */
div {
  padding: 40px;       /* ignored */
  background: blue;    /* ignored */
}
Good CSS
<!-- HTML -->
<div class="card">
  Content
</div>

/* CSS: works normally */
.card {
  padding: 40px;
  background: blue;
}

How to Fix

  • 1Move inline styles to CSS classes. This is always the best fix.
  • 2If you can't change the HTML (third-party widget), use !important as a last resort.
  • 3For JavaScript-set styles, use element.classList.add() instead of element.style.
  • 4Check for inline styles in DevTools: they appear at the top of the Styles panel.

Check Your CSS Now

Our CSS validator detects this error automatically and shows the exact line number.

Open CSS Validator
Recommended

Hostinger Fast & Affordable Web Hosting

Deploy clean, validated CSS on reliable hosting.

Get 80% Off Hosting →

Related CSS Errors

View all CSS errors