Image Caption
Image Caption components are used to group an image with a caption. This component is useful for displaying images with a caption that provides context to the image.
API Reference
This component is based on the <figure>
element and can take in any additional HTML attributes. The following are the custom props that can be passed to the component.
Prop | Type | Default |
---|---|---|
image | HTMLAttributes<'img'> | — |
src * | string | — |
alt * | string | — |
width | number | — |
height | number | — |
decoding | 'async' | 'sync' | 'auto' | — |
loading | 'lazy' | 'eager' | — |
caption | HTMLAttributes<'figcaption'> | — |
text | string | — |
Accessibility
The <ImageCaption>
component has some accessibility considerations baked into it. The following are some of the key accessibility features that are included in the component and worth considering:
- When the image is decorative, the
alt
property can be omitted and will automatically be converted toalt=""
. - If an image has a
caption
, thealt
will default to that caption text unless otherwise specified. - If an image has the same
caption
andalt
text, thecaption
will be given thearia-hidden="true"
attribute to prevent duplication of content to screen readers.
Astro Component
Depending on the framework, it’s sometimes beneficial to use a component. In this case, we have put together the following Astro component to serve as a blueprint for how you could possibly set up an Image Caption component, and what properties to consider.