Skip to content

Getting started

Shadleaf needs Java 17, Spring Boot 4 and Thymeleaf. The jar ships compiled CSS and JavaScript, so a plain Maven build is enough to get started.

Add the dependency to your pom.xml of your Spring Boot with Thymeleaf application:

<dependency>
<groupId>io.github.wimdeblauwe</groupId>
<artifactId>shadleaf-spring-boot-starter</artifactId>
<version>1.0.3</version>
</dependency>

Include the stylesheet and the theme script

Section titled “Include the stylesheet and the theme script”

In the <head> of your layout:

<head>
<th:block th:replace="~{sl/layout :: theme-script}"></th:block>
<th:block th:replace="~{sl/layout :: assets}"></th:block>
<!-- your own stylesheet after it, so your overrides win -->
<link rel="stylesheet" th:href="@{/css/application.css}">
</head>

The theme-script reads the user’s preference from localStorage and sets the class="dark" on <html> before the first paint. Place the <sl:theme-toggle> on your page to let the user choose between light and dark mode.

The assets block renders the CSS and JS links. By default, Alpine.js is loaded and you can use it in your own pages. See Alpine.js if your application loads Alpine itself.

If you want to use Tailwind CSS in your own pages, see Tailwind CSS for how to set it up.

If you have a Content-Security-Policy, see CSP for more information.

Add a component to your Thymeleaf template:

<html xmlns:th="http://www.thymeleaf.org" xmlns:sl="https://shadleaf.dev/sl">
...
<sl:button variant="outline">Cancel</sl:button>
<sl:button type="submit">Save</sl:button>

See the Components section for all available components and their attributes. There are also Layouts with whole page layouts to copy.

Property Default
shadleaf.skin vega The visual identity; see Skin for the list.
shadleaf.assets.variant standalone embedded leaves out Tailwind’s reset, for applications that compile Tailwind themselves.
shadleaf.assets.alpine bundled Where Alpine.js comes from: bundled, csp or external; see Alpine.js.
shadleaf.csp.nonce-attribute cspNonce The request attribute holding a CSP nonce for the theme script.
shadleaf.security.login-url /login Where the user menu’s Sign in link goes; /oauth2/authorization/<id> with one OAuth2 login client. See Spring Security.
shadleaf.security.logout-url /logout Where the user menu’s sign-out form posts to; see Spring Security.
shadleaf.dev.web-types-file Writes IDE metadata for your components; see IDE completion.