Search code examples
javaspringspring-bootspring-mvcthymeleaf

Spring Boot cant serve css file with Thymeleaf View


I am making an app with Spring Boot. I have a Thymeleaf view chat.html in resources/templates/chat.html I include style.css stylesheet in it. When I load the chat.html in browser only html shows without any stylesheet.

Here is chat.html

<html xmlns:th="http://www.thymeleaf.org">
    <head>
        <link href="styles/style.css" rel="stylesheet">
        <title>Chat Web App</title>
    </head>
   ...some irrelevant html ...
    <body>

</body>
</html>

I have put the style.css in resources/static/styles/style.css as per several other answers for same problem but no bueno. Perhaps some additional configuration need to be made or i am simply making a dumb typo.


Solution

  • The issue was actually in my CSS file :) . Apparently i had selectors for classes that werent present in the html. After removing them the solution proposed in the comments worked fine!