Specifies an image that’s used in lightning-carousel, including description and title
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App
Use the lightning-carousel-image component to specify images for the
lightning-carousel component.
You can specify up to six images, which then appear in the order that you
list them in the lightning-carousel component.
For each image, use the src attribute to specify the path to the image.
Optionally use header and description attributes to provide a header
and descriptive text that the carousel shows below the image.
You can also hyperlink the images with the href attribute.
Use the alternative-text attribute to supply assistive text for each image.
Use lightning-carousel-image within lightning-carousel, which implements the carousel blueprint in the Salesforce Lightning Design System (SLDS). The carousel adapts to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use.
To use images in your org, upload them as static resources in the Static Resources
page in Setup. To reference a resource in lightning-carousel-image, use {property}
syntax in your src attribute.
If the image path is invalid or the image doesn’t load because the user is
offline or another reason, the description and alternative text replace the image.
This example uses static resources uploaded as a single image, and images uploaded in a zip file.
1<template>2 <div class="slds-size_1-of-4">3 <lightning-carousel>4 <lightning-carousel-image5 src={companyLogoUrl}6 header="Company logo"7 description="Company logo uploaded to a static resource"8 alternative-text="Company logo"9 >10 </lightning-carousel-image>11 <lightning-carousel-image12 src={product1Url}13 header="Fantastic product 1"14 description="Fantastic product image in a zip file"15 alternative-text="Fantastic product 1"16 >17 </lightning-carousel-image>18 <lightning-carousel-image19 src={product2Url}20 header="Fantastic product 2"21 description="Fantastic product image in a zip file"22 alternative-text="Fantastic product 2"23 >24 </lightning-carousel-image>25 </lightning-carousel>26 </div>27</template>
The company logo was uploaded as a single image to a static resource named company_logo and imported as companyLogo. The Product1 and Product2 images were uploaded in a zip file to a static resource named company_products and imported as companyProducts.
1import{LightningElement}from "lwc";2import companyLogo from "@salesforce/resourceUrl/company_logo";3import companyProducts from "@salesforce/resourceUrl/company_products";45export default class CarouselStaticResources extends LightningElement{6 // Expose the static resource URL for use in the template7 companyLogoUrl = companyLogo;89 // Expose URL of assets included inside an archive file10 product1Url = companyProducts + "/product1.png";11 product2Url = companyProducts + "/product2.png";12}
Accessibility
lightning-carousel-image includes accessibility features provided by lightning-carousel. A carousel image appears with header text and a description. Use the alternative-text attribute to specify assistive text for each image.
lightning-carousel-image observes these roles, states, and properties.
The indicator button (tab’s anchor) of a selected image has aria-selected="true", and all other tabs have aria-selected="false".
The tab’s anchor of a selected image has tabindex="0", and all other tabs have tabindex="-1".
Each image container (tab panel) contains an element with role="tabpanel".
Each tab panel has an aria-labelledby attribute whose value is the ID of its associated indicator button.
Each tab panel has an aria-hidden attribute whose value is toggled based on whether the panel is visible.
Attributes
Name
Description
Type
Default
Required
alternative-text
Assistive text for the image.
string
description
Text displayed under the header.
string
header
Text for the label that's displayed under the image.
string
href
A URL to create a link for the image. Clicking the image opens the link in the same frame.