Skip to content

How to best use responsive WebP images with picture elements ? What about GID and PID ? #2034

Answered by robots4life
robots4life asked this question in Q&A
Discussion options

You must be logged in to vote

In a Svelte component I have this markup.

<a
	href="{pictureData.url}"
	data-pswp-width="{pictureData.width}"
	data-pswp-height="{pictureData.height}"
	data-pswp-srcset="{srcSetWep}"
	target="_blank"
	rel="noreferrer"
>
	<picture>
		<source sizes="200px" srcset="{srcSetWep}" type="image/webp" />
		<img
			src="{pictureData.url}"
			sizes="200px"
			srcset="{srcSet}"
			width="{pictureData.width}"
			height="{pictureData.height}"
			alt="{pictureData.altText.text}"
		/>
	</picture>
</a>

<style>
	img {
		max-width: 200px;
	}
</style>

This works exactly like I wanted it and shows responsive and WebP images in the slideshow, only being marginally wider than the current viewport width due to …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by robots4life
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants