Image
Image
creates optimized images with accessible figcaptions and prevents cumulative layout shift. It uses Astro’s Picture
component under the hood.
-->
Image
creates optimized images with accessible figcaptions and prevents cumulative layout shift. It uses Astro’s Picture
component under the hood.
Google has been extremely vocal about the importance of Cumulative Layout Shift (CLS), so much that it has became part of Google’s Lighthouse audit.
Thankfully, Astro’s built-in Image
and Picture
components handles CLS without us having to lift a finger.
Unfortunately, Astro’s built in Image
and Picture
elements require you to manually import your image, which leaves more to be desired.
We’ve built Image
so you can import images dynamically just like how you’ve been using images all along.
It’s strange, but <figcaption>
elements aren’t accessible. You gotta work out a few quirks to make them accessible. We’ve done this for you so you can just add caption
and call it a day.
There are lots of image formats out there, but the most performant ones are avif
and webp
. We’ve built these two formats into Image
so you can optimize your images without any extra work.
Image
includes srcset
sizes at 600
, 900
, 1200
, 1500
and 1800
pixels to serve appropriate images for almost every device users can use. This lowers your page weight as much as possible.
These values are customizable if you wish to change them.
A simple Image
call produces HTML that does all of the following:
figure
, figcaption
, and alt
text for accessibility.width
and height
values to prevent cumulative layout shifts.avif
and webp
formats and async
decoding for faster image rendering.srcset
values and lazy
loading to reduce bandwidth usage.Pass an src
value to import an image from any folder in /src
. This should be an absolute path to your image.
Use the alt
attribute to pass alt text, just like a normal image. alt
defaults to an empty string when not defined.
Use caption
to create accessible figcaptions.
alt
can be used with caption
. When used in this way, alt
should describe the image while caption
should give additional context about the image.
You can use image properties like decoding
and loading
by adding them to Image
. The following values are set by Astro’s Picture
element by default.
The following additional customizations are best made by creating your own Image
component on top of ours because you would likely want them to be consistent across your site.
Image
creates avif
and webp
formats by default for better performance. You can pass in formats
which takes in an array of available formats to override this default.
Image
optimizes your images and create variants at 600
, 900
, 1200
, 1500
, and 1800
pixels by default. If your image is larger than 1800px
, Image
will also retain the original images for screen sizes beyond 1800px
.
You can customize this by providing an array of widths
you’d like to create.
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
A simple Image
call produces HTML that does all of the following:
figure
, figcaption
, and alt
text for accessibility.width
and height
values to prevent cumulative layout shifts.avif
and webp
formats and async
decoding for faster image rendering.srcset
values and lazy
loading to reduce bandwidth usage.Pass an src
value to import an image from any folder in /src
. This should be an absolute path to your image.
Use the alt
attribute to pass alt text, just like a normal image. alt
defaults to an empty string when not defined.
Use caption
to create accessible figcaptions.
alt
can be used with caption
. When used in this way, alt
should describe the image while caption
should give additional context about the image.
You can use image properties like decoding
and loading
by adding them to Image
. The following values are set by Astro’s Picture
element by default.
The following additional customizations are best made by creating your own Image
component on top of ours because you would likely want them to be consistent across your site.
Image
creates avif
and webp
formats by default for better performance. You can pass in formats
which takes in an array of available formats to override this default.
Image
optimizes your images and create variants at 600
, 900
, 1200
, 1500
, and 1800
pixels by default. If your image is larger than 1800px
, Image
will also retain the original images for screen sizes beyond 1800px
.
You can customize this by providing an array of widths
you’d like to create.
Image
produces the following HTML when caption
is not used.
It produces the following HTML when caption
is used.
We don’t provide basic styles for Image
so you can use your own styles.
That said, we recommend adding the following to your reset.css
file to ensure images are responsive. This, plus other reset styles, are provided in Splendid Styles
You can use the following properties to style Image
with Tailwind:
Property | Description |
---|---|
class | Class for the <figure> element |
imageClass | Class for the <img> element |
captionClass | Class for the <figcaption> element |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
Image
produces the following HTML when caption
is not used.
It produces the following HTML when caption
is used.
We don’t provide basic styles for Image
so you can use your own styles.
That said, we recommend adding the following to your reset.css
file to ensure images are responsive. This, plus other reset styles, are provided in Splendid Styles
You can use the following properties to style Image
with Tailwind:
Property | Description |
---|---|
class | Class for the <figure> element |
imageClass | Class for the <img> element |
captionClass | Class for the <figcaption> element |
You can use the following properties to style Image
with Tailwind:
Property | Description |
---|---|
class | Class for the <figure> element |
imageClass | Class for the <img> element |
captionClass | Class for the <figcaption> element |
You can use these properties to adjust the Image
’s output.
Property | Type | Description |
---|---|---|
src | string | Source of the image. This should be an absolute url from your project root. |
alt | string | Alt text |
caption | string | Caption text |
formats | array | Image formats to create and optimize for. |
widths | array | srcset sizes to create and optimize for. |
Splendid Labz is free because we love developers and we want to contribute back to the ecosystem.
We only charge for access to the documentation to keep the project going. If you don't wish to pay, feel free to use the content from the features tab, our blogs or our videos as your guide.
You can use the following properties to style Image
with Tailwind:
Property | Description |
---|---|
class | Class for the <figure> element |
imageClass | Class for the <img> element |
captionClass | Class for the <figcaption> element |
You can use these properties to adjust the Image
’s output.
Property | Type | Description |
---|---|---|
src | string | Source of the image. This should be an absolute url from your project root. |
alt | string | Alt text |
caption | string | Caption text |
formats | array | Image formats to create and optimize for. |
widths | array | srcset sizes to create and optimize for. |