Responsive, lazily-loaded images with Svelte and Imgix
srcsets
automaticallynpm i svelte-imgix
<script>
import Imgix from 'svelte-imgix';
</script>
<Imgix
src="https://assets.imgix.com/image.jpg"
/>
Svelte-Imgix automatically generates a responsive srcset
for a huge range of viewport sizes. By adding a sizes
attribute to your image you can instruct the browser to use the appropriate source based on media queries.
See the MDN article on responsive images for a thorough walkthrough.
You can either provide a full Imgix URL (with query parameters) to svelte-imgix
, or define parameters to override anything set on the src with the imgixParams
prop. All valid Imgix properties are avaiable.
<Imgix
src="https://assets.imgix.com/image.jpg"
imgixParams={{
auto: 'format',
fit: 'facearea'
}}
/>
Property | Type | Description |
---|---|---|
src |
string |
Imgix source of the image |
alt |
string |
Alt text for the image |
ImgixParams |
object |
Object of Imgix parameters to set on the image, overrides any defaults given in src |