title: Thymeleaf URL expression in .css file
body: <p>I'm using Spring MVC and the Thymeleaf view engine. I have an external <strong><em>style.css</em></strong> file with the CSS for my page. In the CSS file, I want to refer to a relative image URL.</p>
  
  <p>This is my <strong><em>style.css</em></strong> file:</p>
  
  <pre><code>.background {
      width: 100%;
      background-image: url('/path/to/image/bg.png');
  }
  </code></pre>
  
  <p>The above tries to access an image with the following URL, which doesn't exist:</p>
  
  <pre><code>http://localhost/path/to/image/bg.png
  </code></pre>
  
  <p>My real image is at:</p>
  
  <pre><code>http://localhost/myapp/path/to/image/bg.png
  </code></pre>
  
  <p>This StackOverflow question gives the answer to my question for inline CSS: <a href="https://stackoverflow.com/questions/35789526/how-to-set-background-url-for-css-files-in-thymeleaf">How to set background url for css files in thymeleaf?</a></p>
  
  <p>But how do I do this for an external .css file?</p>