4

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" />

2 Answers 2

4

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'"
/>
4

The correct way for building of srcset attribute in thymeleaf is as follows:

<img th:attr="srcset=|@{/img/image1x.png} 1x, @{/img/image2x.png} 2x, @{/img/image3x.png} 3x|" th:src="@{/img/image1x.png}" alt="My image description text" />

Not the answer you're looking for? Browse other questions tagged or ask your own question.