Thymeleaf + CSS+SpringBoot

Luca Sepe picture Luca Sepe · Jan 11, 2017 · Viewed 40.7k times · Source

I have a problem with CSS and Thymeleaf.

In my Spring boot app, I have this structure:

  • src/main/resource/static/css (for css files)
  • src/main/resource/static/templates (for html file)

Now, with my html page named ErrorPage and css file named Layout.css, using Thymeleaf I have, in the head of ErrorPage:

<link href="../css/Layout.css" th:href="@{css/Layout.css}" type="text/css" />

But this does not work.

What am I doing wrong?

Answer

DimaSan picture DimaSan · Jan 11, 2017

Move your template folder right under resources:

  • src/main/resource/static/css (for CSS files);
  • src/main/resource/templates (for HTML templates).

Then correct the link tag as follows:

<link href="../static/css/Layout.css" th:href="@{/css/Layout.css}" rel="stylesheet" />