Skip to main content

HTML Guide

CSS: “background-image”: X is not a “background-image” value.

background-image attribute values must use valid CSS syntax.

The background-image property in CSS expects the value to be a valid image reference, such as none, url("image.png"), gradients, or inherit.

Correct CSS Syntax:

background-image: url("background.jpg");

Correct usage in HTML (inline style):

<div style="background-image: url('background.jpg');">
  Content here
</div>

Incorrect usage (missing url() or filename only):

<div style="background-image: background.jpg;">
  Content here
</div>

Correct usage in a <style> block:

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Background Image Example</title>
    <style>
      .banner {
        background-image: url("banner.png");
      }
    </style>
  </head>
  <body>
    <div class="banner">Welcome</div>
  </body>
</html>

Always wrap the image path with the url() function and use quotes for paths containing special characters.

Learn more:

Related W3C validator issues