Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build srcset attribute with Thymeleaf

What would be the correct way to build a srcset-attribute with Thymeleaf using the standart url syntax @{/...} ?

Example:

<img th:src="@{/i/1000.jpg}" srcset="/i/1500.jpg 1500w, /i/2000.jpg 2000w" />
like image 919
yglodt Avatar asked Sep 11 '25 15:09

yglodt


1 Answers

Nevermind, it was easier than expected and logical at the same time:

<img
    th:src="@{/i/1000.jpg}"
    th:attr="srcset=@{/i/1500.jpg} + ' 1500w, ' + @{/i/2000.jpg} + ' 2000w'"
/>
like image 97
yglodt Avatar answered Sep 13 '25 10:09

yglodt