Label
Thymeleaf source
<sl:label for="label-email">Email</sl:label><sl:input type="email" id="label-email" placeholder="you@example.com"/>Rendered HTML
<label class="label" for="label-email">Email</label><input class="input" type="email" id="label-email" placeholder="you@example.com">Pointing at a control
Section titled “Pointing at a control”Give the label a for with the control’s id. A control with th:field="*{email}" gets id="email" from Spring, so
for="email" matches it without writing the id yourself. Clicking the label focuses the control, and a screen
reader announces the label’s text as the control’s name.
A label can also hold its control, and then needs no for:
Thymeleaf source
<sl:label><input type="checkbox" name="newsletter"> Send me the newsletter</sl:label>Rendered HTML
<label class="label"> <input type="checkbox" name="newsletter"> Send me the newsletter</label>In a field, use <sl:field-label>: it points at the field’s control by itself.
Disabled
Section titled “Disabled”A label fades with a disabled control it holds, or one right before or after it, including a control disabled by a
<fieldset disabled> around it. There is nothing to add to the label.
Attributes
Section titled “Attributes”sl:label declares no props; every attribute passes through.