# developer Lightning Component Reference (lightning-base-components) - Full Documentation # Accordion **`lightning-accordion`** A collection of vertically stacked sections with multiple content areas. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="accordion" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-accordion` component shows vertically stacked sections of content that you can expand and collapse. Click a section's header to expand its content. Users can control how much content is visible without scrolling as much to see the content of a page. To create an accordion section, nest a [`lightning-accordion-section`](/docs/platform/lightning-component-reference/guide/lightning-accordion-section.html) component within `lightning-accordion`. Each `lightning-accordion-section` can contain HTML markup or Lightning components. By default, you can open only one section at a time. Close a section by opening another section. You can configure the accordion to allow multiple sections to be open, and then click the section headers to open and close the section. **note:** You can specify one or more active sections. Active sections are expanded when the component loads. This documentation uses the terms "active", "expanded", and "open" interchangeably. `lightning-accordion` doesn't support lazy loading. The content you load in inactive sections also impact your page load time. ## Design `lightning-accordion` implements the accordion blueprint in the Salesforce Lightning Design System (SLDS). The accordion adapts to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Accordion](https://v1.lightningdesignsystem.com/components/accordion/) | [Accordion](https://www.lightningdesignsystem.com/components/accordion/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Initialize the Accordion with an Active Section The first accordion section is expanded by default. To change the default, provide a section name by using the `active-section-name` attribute. The section name is case-sensitive. This example creates a basic accordion with three sections, where section B is expanded by default. Only one accordion section is expanded at a time. ```html ``` If two or more sections use the same name and that name is also specified as the `active-section-name`, the first section with that name is expanded by default. **tip:** To view interactive examples, see the [Examples tab](/docs/platform/lightning-component-reference/guide/lightning-accordion.html?type=Example). ## Initialize the Accordion with Multiple Active Sections To specify multiple expanded sections, include `allow-multiple-sections-open` in your markup and pass in an array of accordion section names to `active-section-name`. If you don't pass in a section name, all sections are closed by default. ```html ``` In your JavaScript code, define the sections you want to expand. ```javascript import { LightningElement } from "lwc"; export default class LightningExampleAccordionMultiple extends LightningElement { activeSections = ["A", "C"]; } ``` ## Handle the Section Toggle Event When the open sections change, use the `onsectiontoggle` handler to find out which sections are active. This example shows the name of the active section. ```html ``` Use the `detail.openSections` property to return the active section names. ```javascript import { LightningElement } from "lwc"; export default class DemoAccordionMultiple extends LightningElement { activeSectionsMessage = ""; handleSectionToggle(event) { const openSections = event.detail.openSections; if (openSections.length === 0) { this.activeSectionsMessage = "All sections are closed"; } else { this.activeSectionsMessage = "Open sections: " + openSections.join(", "); } } } ``` The `openSections` event parameter returns a string or an array of strings depending on the `allow-multiple-sections-open` attribute. - If you include the `allow-multiple-sections-open` attribute, `openSections` returns an array. For example: `['A']` for an open accordion section and `['A', 'B']` for multiple open accordion sections. An accordion section without a `name` value or a `name` value that contains an empty string is excluded from the `openSections` array. If only this accordion section is opened, `openSections` returns an empty array and `openSections.length` returns 0. If none of the accordion sections include a `name` value, `openSections` returns an empty array and `openSections.length` returns 0 when any number of accordion sections are opened. - If you don't include the `allow-multiple-sections-open` attribute, `openSections` returns a string. For example: `A` for an open accordion section. In this case, only one section can be open at a time. If an accordion section without a `name` attribute or a `name` value that contains an empty string is opened, `openSections` returns undefined. ## Expand Sections Programmatically To expand a section, pass in the section name by using `active-section-name`. This example expands section B when the **Expand Section B** button is pressed. ```html ``` The `onclick` handler on the button sets the active section name, which opens the section programmatically. Set the value for the open section by using the `openSections` property in the `onsectiontoggle` handler. ```javascript import { LightningElement } from "lwc"; export default class App extends LightningElement { section = ""; handleClick(event) { this.section = "B"; } handleSectionToggle(event) { this.section = event.detail.openSections; } } ``` To expand multiple sections programmatically, include `allow-multiple-sections-open` in your markup and pass in an array of section names instead. ```javascript import { LightningElement } from "lwc"; export default class App extends LightningElement { section = []; handleClick(event) { this.section = ["B", "C"]; } handleSectionToggle(event) { this.section = event.detail.openSections; } } ``` ## Conditionally Show an Accordion Section To toggle the visibility of an accordion section, use the [`if:true` directive](https://developer.salesforce.com/docs/platform/lwc/guide/create-conditional.html). ```html ``` ## Component Styling `lightning-accordion` adapts to [SLDS 1](https://v1.lightningdesignsystem.com/components/accordion/) and [SLDS 2](https://www.lightningdesignsystem.com/components/accordion/) styling. To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds a border and gray background to the accordion content area by using SLDS classes. ```html

This is the content area for section A.

``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Usage Considerations You can't initialize an accordion with multiple sections by using only markup. Pass the array of section names using JavaScript, as described in [Initialize the Accordion with Multiple Active Sections](#initialize-the-accordion-with-multiple-active-sections). Accordion sections aren’t lazy loaded. Content in sections that are collapsed initially are available on load in the DOM. This component has usage differences from its Aura counterpart. See [Base Components: Aura Vs Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/migrate-map-aura-lwc-components) in the Lightning Web Components Developer Guide. ## Accessibility `lightning-accordion` implements the [SLDS accordion blueprint](https://v1.lightningdesignsystem.com/components/accordion), which follows the [WAI-ARIA Authoring Practices for the accordion pattern](https://www.w3.org/WAI/ARIA/apg/patterns/accordion/). In addition to the keyboard interaction guidelines on the WAI-ARIA site, you can use the Left Arrow and Right Arrow key to move focus from an accordion header. The Home and End keys aren’t used for keyboard interaction on `lightning-accordion`. `lightning-accordion` observes these roles, states, and properties. - `lightning-accordion` has `role="list"`. - When you set `active-section-name` to expand specific sections, the button on those section headers uses `aria-expanded` set to `true`. - An accordion section sets `aria-hidden` to `true` if the section is collapsed, which hides the content from assistive technologies. ## Custom Events **`sectiontoggle`** The event that's fired when an accordion loads with at least one active section or when a section is toggled. The `sectiontoggle` event returns this parameter. | Parameter | Type | Description | | ------------ | ------ | ----------------------------------------------------------------------------------------- | | openSections | object | The name of the active section. Returns an array of strings for the active section names. | The event properties are as follows. | Property | Value | Description | | ---------- | ----- | --------------------------------------------------------------------------------------------------------- | | bubbles | false | This event doesn’t bubble. | | cancelable | false | This event has no default behavior that can be canceled. You can't call `preventDefault()` on this event. | | composed | false | This event doesn’t propagate outside the template in which it was dispatched. | ::::: :::::tab ::component-specification{component="accordion" model="lwc" namespace="lightning"} ::::: :::::: # Accordion Section **`lightning-accordion-section`** A single section that is nested in an accordion component. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="accordionSection" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-accordion-section` component defines the content of an accordion section inside a [`lightning-accordion`](/docs/platform/lightning-component-reference/guide/lightning-accordion.html) component. Each section can contain HTML markup or Lightning components. This example creates a basic accordion with three sections, where section B is expanded by specifying it with the `active-section-name` attribute in `lightning-accordion`. ```html ``` Use the `label` attribute to provide optional header text for an accordion section. When the header text is too long to display in the viewport, the text is truncated and displayed with an ellipsis on desktop screens. Hover with the mouse to see the full text. On mobile devices, long header text wraps to multiple lines because hover text isn't available. To expand or collapse a section, click the toggle button or header text. ## Design Use `lightning-accordion-section` within `lightning-accordion`, which implements the accordion blueprint in the Salesforce Lightning Design System (SLDS). The accordion adapts to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Accordion](https://v1.lightningdesignsystem.com/components/accordion/) | [Accordion](https://www.lightningdesignsystem.com/components/accordion/) | | **For Use In** | Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Add an Action Menu This example creates the same basic accordion with an added `lightning-button-menu` on the first section. The button menu is assigned to the `actions` slot which makes it display on the section header. ```html ``` ## Component Styling To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. For more information, see [`lightning-accordion`](/docs/platform/lightning-component-reference/guide/lightning-accordion.html). ## Usage Considerations If two or more sections use the same name and that name is also specified as the `active-section-name`, the first section using that name is expanded by default. This component has usage differences from its Aura counterpart. See [Base Components: Aura Vs Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/migrate-map-aura-lwc-components) in the Lightning Web Components Developer Guide. ## Accessibility `lightning-accordion-section` renders the toggle button and title in a ` ``` ```javascript import LightningAlert from 'lightning/alert'; jest.mock('lightning/alert'); ​ test(() => { // Create and appendChild(element) ​ const buttonEle = element.shadowRoot.querySelector('[data-button]'); const textEle = element.shadowRoot.querySelector('[data-text]'); ​ // Mock .open() // No value passed since LightningAlert doesn't have a return value LightningAlert.open = jest.fn().mockResolvedValue(); // Initial value expect(textEle.textContent).toBe('Click to View Content'); // Click modal open button buttonEle.click(); ​ // Click handler render cycle await Promise.resolve(); // Render cycle triggered by tracked value {result} await Promise.resolve(); ​ // Verify alertViewed has updated in template expect(textEle.textContent).toBe('Content Viewed'); // Open triggered once expect(LightningAlert.open.mock.calls).toHaveLength(1); }) ``` ## Accessibility The `lightning/alert` module implements the SLDS [prompt blueprint](https://v1.lightningdesignsystem.com/components/prompt/#site-main-content), which follows the [WAI-ARIA Authoring Practices for the alert and message dialogs pattern](https://www.w3.org/WAI/ARIA/apg/patterns/alertdialog/). Like modals, the alert dialog is a focus trap, but it specifies `role="alertdialog"` to indicate its severity. Use the keyboard interaction guidelines on the SLDS site. When the dialog opens, focus moves to the header text on the dialog, which has `tabindex="-1"`. To close the dialog, you can press the Esc key. Alternatively, you can tab to the OK button and press Enter. `lightning/alert` observes these roles, states, and properties. - The section element has `role="alertdialog"` with an `aria-description`, which uses the value you provide for the `message` attribute. - The `aria-labelledby` value on the section is set to the ID of the header text. Provide a header text by using the `label` attribute. ::::: :::::tab ::component-specification{component="alert" model="lwc" namespace="lightning"} ::::: :::::: # Allow Guest Access **`ltng:allowGuestAccess`** Allows guest user access on an application. **For Use In** Lightning Out (Beta) ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab Add the `ltng:allowGuestAccess` interface to your Lightning Out dependency app to make it available to users without requiring them to authenticate with Salesforce. This interface lets you build your app with Lightning components, and deploy it anywhere and to anyone. A Lightning Out dependency app with the `ltng:allowGuestAccess` interface can be used with Lightning Components for Visualforce and with Lightning Out. - Using Lightning Components for Visualforce, you can add your Lightning app to a Visualforce page, and then use that page in Salesforce Tabs + Visualforce sites. Then you can allow public access to that page. - Using Lightning Out, you can deploy your Lightning app anywhere Lightning Out is supported—which is almost anywhere! The `ltng:allowGuestAccess` interface is only usable in orgs that have Digital Experiences enabled, and your Lightning Out app is associated with all Experience Cloud site endpoints that you’ve defined in your org. Experience Cloud sites include sites built using Experience Builder and Visualforce. When you add the `ltng:allowGuestAccess` interface to a Lightning app, the app is open to guest users and is available through _every_ Experience Builder site in your org, whether that site is enabled for public access or not. You can’t prevent it from being accessible via site URLs, and you can’t make it available for some sites but not others. Be extremely careful about apps you open for guest access. Apps enabled for guest access bypass the object- and field-level security (FLS) you set for your Experience Cloud site’s guest user profile. Lightning components don’t automatically enforce CRUD and FLS when you reference objects or retrieve the objects from an Apex controller. This means that the framework continues to display records and fields for which users don’t have CRUD access and FLS visibility. You must manually enforce CRUD and FLS in your Apex controllers. A mistake in code used in an app enabled for guest access can open your org’s data to the world. ## Usage First, add the `ltng:allowGuestAccess` interface to your Lightning Out dependency app. For example: ```xml ``` You can only add the `ltng:allowGuestAccess` interface to Lightning apps, not to individual components. Next, add the Lightning Out JavaScript library to your page. - With Lightning Components for Visualforce, simply add the `` tag anywhere on your page. - With Lightning Out, add a ` ``` A sample URL for the JavaScript library is `https://universalcontainers.force.com/ourstores/lightning/lightning.out.js` Finally, add the JavaScript code to load and activate your Lightning app. This code is standard Lightning Out, with the important addition that you must use one of your org’s Experience Cloud site URLs for the endpoint. The endpoint URL takes the form `https://yourExperienceDomain/experienceURL/`. The relevant line is emphasized in the following sample. ```html ``` For more information, see the [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/lightning_out.htm). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Allow In Relaxed CSP **`lightningcommunity:allowInRelaxedCSP​`** Enables a component to be used in a Relaxed CSP Experience Builder site. **For Use In** Experience Builder Sites ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab Add the `lightningcommunity:allowInRelaxedCSP`​ interface to enable this component to run in an Aura-based Experience Builder site that has Lightning Locker disabled. If this interface is not implemented, and Lightning Locker is disabled, your component won't be rendered in runtime, and won't be available in design time. This example shows the markup required to add the `lightningcommunity:allowInRelaxedCSP`​ interface. ```xml ``` For more information, see [Enable Third-Party Components to Run When Lightning Locker Is Off](https://developer.salesforce.com/docs/atlas.en-us.communities_dev.meta/communities_dev/communities_dev_security_locker_off_components.htm) in the _Experience Cloud Developer Guide_. ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Analytics Interaction **`forceCommunity:analyticsInteraction`** Tracks events that are triggered by custom components in Aura-based Experience Builder sites and sends the data to Google Analytics. **For Use In** Experience Builder Sites ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab This example creates a custom button and includes the `forceCommunity:analyticsInteraction` event in the button's client-side controller. Clicking the button sends event data to Google Analytics. ```javascript handleClick : function(cmp, event, helper) { var analyticsInteraction = $A.get("e.forceCommunity:analyticsInteraction"); analyticsInteraction.setParams({ hitType : 'event', eventCategory : 'Button', eventAction : 'click', eventLabel : 'Winter Campaign Button', eventValue: 200 }); analyticsInteraction.fire(); } ``` This event is supported in Aura-based Experience Builder sites only. To enable event tracking, add your Google Analytics tracking ID in Settings | Advanced in Experience Builder and publish the site. Google Analytics isn’t supported in sandbox environments. ::::: :::::tab ## Attributes | Name | Description | Type | Default | Required | | ---------------- | -------------------------------------------------------------------------------------------------------- | ------- | ------- | -------------------------------------------- | | `eventAction` | The type of action. Required for 'event' hitType. | string | | | | `eventCategory` | The type or category of item that was interacted with. Required for 'event' hitType. | string | | | | `eventLabel` | A label for providing additional event information. | string | | | | `eventValue` | A positive numeric value associated with the event. | integer | | | | `exDescription` | A description of the exception. | string | | | | `exFatal` | True if the exception was fatal. | boolean | | | | `hitType` | The type of hit. Supported types: 'event', 'social', 'exception', 'timing'. | string | | ![Yes](https://developer.salesforce.com/media/check.png) | | `socialAction` | The type of action that happens. Required for 'social' hitType. | string | | | | `socialNetwork` | The network on which the action occurs. Required for 'social' hitType. | string | | | | `socialTarget` | Specifies the target of a social interaction. Required for 'social' hitType. | string | | | | `timingCategory` | A string for categorizing all user timing variables into logical groups. Required for 'timing' hitType. | string | | | | `timingLabel` | A string that can be used to add flexibility in visualizing user timings in the reports. | string | | | | `timingValue` | The number of milliseconds in elapsed time to report to Google Analytics. Required for 'timing' hitType. | integer | | | | `timingVar` | A string to identify the variable being recorded. Required for 'timing' hitType. | string | | | ::::: :::::: # Analytics Interaction Gtag **`forceCommunity:analyticsInteractionGtag`** Tracks events that are triggered by custom components in Aura-based Experience Builder sites and sends the data to Google Analytics. **For Use In** Experience Builder Sites ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab This example creates a custom button and includes the `forceCommunity:analyticsInteractionGtag` event in the button's client-side controller. Clicking the button sends event data to Google Analytics. ```javascript handleClick : function(cmp, event, helper) { var analyticsInteraction = $A.get("e.forceCommunity:analyticsInteractionGtag"); analyticsInteraction.setParams({ event : 'click', event_category : 'Button', event_label : 'Winter Campaign Button', value: 200 }); analyticsInteraction.fire(); } ``` This example sends a user timing event to Google Analytics indicating that it took 3549 milliseconds for the current web page to load all external JavaScript dependencies. (Credit to Google Analytics documentation.) ```javascript handleClick : function(cmp, event, helper) { if (window.performance) { // Gets the number of milliseconds since page load // (and rounds the result since the value must be an integer). var timeSincePageLoad = Math.round(performance.now()); var analyticsInteraction = $A.get("e.forceCommunity:analyticsInteractionGtag"); analyticsInteraction.setParams({ event : 'timing_complete', name : 'load', value : 3549, event_category: 'JS Dependencies', event_label: 'Google CDN' }); analyticsInteraction.fire(); } } ``` This example sends an exception event to Google Analytics if the divisor y is zero. (Credit to Google Analytics documentation.) ``` handleClick : function(cmp, event, helper) { var x = component.get("v.x"); var y = component.get("v.y"); try { var r = divide(x, y); } catch(err) { var analyticsInteraction = $A.get("e.forceCommunity:analyticsInteractionGtag"); analyticsInteraction.setParams({ event : 'exception', description : err, fatal : false }); analyticsInteraction.fire(); } } ``` This event is supported in Aura-based Experience Builder sites only. To enable event tracking, add your Google Analytics tracking ID in Settings | Advanced in Experience Builder and publish the site. ::::: :::::tab ## Attributes | Name | Description | Type | Default | Required | | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------- | -------------------------------------------- | | `description` | A description of the error. | string | | | | `event` | The string that will appear as the event action in Google Analytics Event reports. | string | | ![Yes](https://developer.salesforce.com/media/check.png) | | `event_category` | An event category is a name that you supply as a way to group objects that you want to analyze. Also, a string for categorizing all user timing variables into logical groups. | string | | | | `event_label` | Provides additional information for events that you want to analyze. Also, a string that can be used to add flexibility in visualizing user timings in the reports. | string | | | | `fatal` | True if the error was fatal. | boolean | | | | `name` | A string to identify the variable being recorded. Required for 'timing_complete' event. | string | | | | `value` | An integer used to assign a numerical value to a page object. Also, he number of milliseconds in elapsed time to report to Google Analytics. Required for 'timing_complete' event. | integer | | | ::::: :::::: # API Modules Access Salesforce data, platform features, and specialized APIs with wire adapters and functions. ## Record Data Access record data, object metadata, and list information using these UI API modules. - [GraphQL API](https://developer.salesforce.com/docs/platform/lwc/guide/reference-lightning-graphql-module.html) - [UI Apps API](/docs/platform/lightning-component-reference/guide/lightning-ui-apps-api.html) - [UI Layout API](/docs/platform/lightning-component-reference/guide/lightning-ui-layout-api.html) - [UI Lists API](/docs/platform/lightning-component-reference/guide/lightning-ui-lists-api.html) - [UI Record API](/docs/platform/lightning-component-reference/guide/lightning-ui-record-api.html) - [UI Object Info API](/docs/platform/lightning-component-reference/guide/lightning-ui-object-info-api.html) - [UI Related List API](/docs/platform/lightning-component-reference/guide/lightning-ui-related-list-api.html) ## Commerce API Manage carts, register guest buyers, and retrieve pricing and product details for a webstore using these Commerce API modules. - [Commerce Cart API](/docs/platform/lightning-component-reference/guide/lightning-commerce-cart-api.html) - [Commerce Register Guest Buyer API](/docs/platform/lightning-component-reference/guide/lightning-commerce-register-guest-buyer-api.html) - [Commerce Repricing API](/docs/platform/lightning-component-reference/guide/lightning-commerce-repricing-api.html) ## Lightning Console API Build enhanced console apps with workspace, utility bar, and messaging features using these Console API modules. - [Conversation Toolkit API](/docs/platform/lightning-component-reference/guide/lightning-conversation-toolkit-api.html) - [Navigation Item API](/docs/platform/lightning-component-reference/guide/lightning-platform-navigation-item-api.html) - [Platform Utility Bar API](/docs/platform/lightning-component-reference/guide/lightning-platform-utility-bar-api.html) - [Platform Workspace API](/docs/platform/lightning-component-reference/guide/lightning-platform-workspace-api.html) ## More Salesforce APIs Integrate Agentforce, CRM Analytics, CMS content, and other data sources using these API modules. - [Agentforce Conversation Client API](/docs/platform/lightning-component-reference/guide/lightning-acc-api.html) - [Analytics Wave API](/docs/platform/lightning-component-reference/guide/lightning-analytics-wave-api.html) - [CMS Delivery API](/docs/platform/lightning-component-reference/guide/lightning-cms-delivery-api.html) - [CMS Editor API](/docs/platform/lightning-component-reference/guide/lightning-cms-editor-api.html) - [Emp API](/docs/platform/lightning-component-reference/guide/lightning-emp-api.html) - [Industries Education Public API](/docs/platform/lightning-component-reference/guide/lightning-industries-education-public-api.html) - [Service Cloud Voice Toolkit API](/docs/platform/lightning-component-reference/guide/lightning-service-cloud-voice-toolkit-api.html) - [Service Knowledge API](/docs/platform/lightning-component-reference/guide/lightning-service-knowledge-api.html) - [UI Learning Platform API](/docs/platform/lightning-component-reference/guide/lightning-ui-learning-platform-api.html) # App Home Template **`lightning:appHomeTemplate`** Indicates the component can be used as a flexipage page template for the APP_PAGE page type. **For Use In** Lightning Experience, Salesforce Mobile App ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab Implement the `lightning:appHomeTemplate` interface to enable your component to be used as a custom Lightning page template for pages of type App Page. This interface has no effect except when used within Lightning Experience and the Salesforce app. Components that implement this interface appear in the Custom Templates section of the Lightning App Builder new page wizard for app pages. Each template component should implement only one template interface. Template components shouldn’t implement any other type of interface, such as `flexipage:availableForAllPageTypes` or `force:hasRecordId`. A template component can’t multi-task as a regular Lightning component. It’s either a template, or it’s not. ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # App Hostable **`force:appHostable`** Enables an Aura component to be used as a custom tab. **For Use In** Lightning Experience, Salesforce Mobile App ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab Add the `force:appHostable` interface to an Aura component to allow it to be used as a custom tab in Lightning Experience or the Salesforce mobile app. Components that implement this interface can be used to create tabs in both Lightning Experience and the Salesforce mobile app. This interface is a marker interface. A marker interface is a signal to the component’s container to add the interface’s behavior to the component. You don’t need to implement any specific methods or attributes in your component, you simply add the interface name to the component’s `implements` attribute. ## Example ```xml

My Tab

``` The `force:appHostable` interface makes the component available for use as a custom tab. For more information, see [Add Lightning Components as Custom Tabs in a Lightning App](https://help.salesforce.com/s/articleView?id=platform.aura_add_cmp_lex.htm). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Application Event **`aura:applicationEvent`** The root event of the event hierarchy for all events of `type="APPLICATION"`. ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab An application event is a form of communication between Aura components anywhere in the application, even if they aren't in the same parent-child containment hierarchy. It follows a traditional publish-subscribe model. For more information, see [Application Events](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application.htm) in the _Lightning Aura Components Developer Guide_. ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Asset Loaded **`wave:assetLoaded`** Indicates that an Analytics asset has finished loading. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab The `wave:assetLoaded` event is sent when an Analytics asset has finished loading. For more information, see the [Analytics Web SDK Dev Guide](https://developer.salesforce.com/docs/atlas.en-us.bi_dev_guide_sdk.meta/bi_dev_guide_sdk/bi_sdk_web.htm). ::::: :::::tab ## Attributes | Name | Description | Type | Default | Required | | ------ | --------------------------------------------------- | ------ | ------- | -------------------------------------------- | | `id` | The identifier of the Analytics asset which loaded. | string | | ![Yes](https://developer.salesforce.com/media/check.png) | | `type` | The type of the Analytics asset which loaded. | string | | ![Yes](https://developer.salesforce.com/media/check.png) | ::::: :::::: # Aura Components **note:** Use Lightning Web Components (LWC) where possible for new development. For more information, see [Migrate Aura Components](https://developer.salesforce.com/docs/platform/lwc/guide/migrate-introduction.html). Salesforce provides prebuilt components that use the Aura programming model. Components in the [`lightning`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura-lightning.md) namespace are known as Lightning base components, which implement Salesforce Lightning Design System (SLDS) component designs and blueprints. Lightning base components include the Aura components listed in this section and Lightning web components listed in the [Components](https://developer.salesforce.com/docs/platform/components.md) section. Aura components are available in these namespaces. - [`lightning`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura-lightning.md) - [`aura`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/aura-namespace.md) - [`force`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/force/aura-force.md) - [`forceChatter`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/forceChatter/aura-forceChatter-namespace.md) - [`forceCommunity`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/forceCommunity/aura-forceCommunity-namespace.md) - [`lightningcommunity`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightningcommunity/aura-lightningcommunity-namespace.md) - [`ltng`](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/ltng/aura-ltng-namespace.md) - [`ui` (deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura-ui.md) ## See Also [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/) # Aura Events **note:** Use Lightning Web Components (LWC) where possible for new development. For more information, see [Migrate Events](https://developer.salesforce.com/docs/platform/lwc/guide/migrate-events.html). Aura events enable communication between components. Handle these events in your custom component to respond to changes in Lightning Experience, Salesforce mobile app, and Aura-based Experience Builder sites. ## Aura Framework Events Customize component behavior using these events. - [Application Event](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/applicationEvent/aura-application-event.md) - [Component Event](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/componentEvent/aura-component-event.md) - [Done Rendering](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/doneRendering/aura-done-rendering.md) (Deprecated) - [Done Waiting](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/doneWaiting/aura-done-waiting.md) (Deprecated) - [Location Change](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/locationChange/aura-location-change.md) - [Method Call](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/methodCall/aura-method-call.md) - [No Access](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/noAccess/aura-no-access.md) - [System Error](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/systemError/aura-system-error.md) - [Value Change](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/valueChange/aura-value-change.md) - [Value Destroy](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/valueDestroy/aura-value-destroy.md) - [Value Event](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/valueEvent/aura-value-event.md) - [Value Init](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/valueInit/aura-value-init.md) - [Value Render](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/valueRender/aura-value-render.md) - [Waiting](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura/waiting/aura-waiting.md) ## Component Events Customize UI component behavior with these events. - [Clear Error](/docs/platform/lightning-component-reference/guide/ui-clear-errors.html) - [Collapse](/docs/platform/lightning-component-reference/guide/ui-collapse.html) - [Expand](/docs/platform/lightning-component-reference/guide/ui-expand.html) - [Menu Focus Change](/docs/platform/lightning-component-reference/guide/ui-menu-focus-change.html) (Deprecated) - [Menu Select](/docs/platform/lightning-component-reference/guide/ui-menu-select.html) (Deprecated) - [Menu Trigger Press](/docs/platform/lightning-component-reference/guide/ui-menu-trigger-press.html) (Deprecated) - [Validation Error](/docs/platform/lightning-component-reference/guide/ui-validation-error.html) (Deprecated) ## Chatter Events Customize Chatter feed behavior using these events. - [Custom Open File](/docs/platform/lightning-component-reference/guide/forceChatter-custom-open-file.html) - [Post Created](/docs/platform/lightning-component-reference/guide/forceChatter-post-created.html) ## Console Chat Events Customize chat behavior in console apps using these events. - [Conversation Agent Send](/docs/platform/lightning-component-reference/guide/aura-conversation-agent-send.html) - [Conversation Chat Ended](/docs/platform/lightning-component-reference/guide/aura-conversation-chat-ended.html) - [Conversation Custom Event](/docs/platform/lightning-component-reference/guide/aura-conversation-custom-event.html) - [Conversation New Message](/docs/platform/lightning-component-reference/guide/aura-conversation-new-message.html) ## Console Omni-Channel Events Customize Omni-Channel behavior in console apps using these events. - [Omni-Channel Connection Error](/docs/platform/lightning-component-reference/guide/aura-omni-channel-connection-error.html) - [Omni-Channel Login Success](/docs/platform/lightning-component-reference/guide/aura-omni-channel-login-success.html) - [Omni-Channel Logout](/docs/platform/lightning-component-reference/guide/aura-omni-channel-logout.html) - [Omni-Channel Status Changed](/docs/platform/lightning-component-reference/guide/aura-omni-channel-status-changed.html) - [Omni-Channel Work Accepted](/docs/platform/lightning-component-reference/guide/aura-omni-channel-work-accepted.html) - [Omni-Channel Work Assigned](/docs/platform/lightning-component-reference/guide/aura-omni-channel-work-assigned.html) - [Omni-Channel Work Closed](/docs/platform/lightning-component-reference/guide/aura-omni-channel-work-closed.html) - [Omni-Channel Work Declined](/docs/platform/lightning-component-reference/guide/aura-omni-channel-work-declined.html) - [Omni-Channel Work Flag Updated](/docs/platform/lightning-component-reference/guide/aura-omni-channel-work-flag-updated.html) - [Omni-Channel Workload Changed](/docs/platform/lightning-component-reference/guide/aura-omni-channel-workload-changed.html) ## CRM Analytics Events Customize CRM Analytics behavior using these events. - [Asset Loaded](/docs/platform/lightning-component-reference/guide/wave-asset-loaded.html) - [Discover](/docs/platform/lightning-component-reference/guide/wave-discover.html) - [Discover Response](/docs/platform/lightning-component-reference/guide/wave-discover-response.html) - [Page Change](/docs/platform/lightning-component-reference/guide/wave-page-change.html) - [Selection Changed](/docs/platform/lightning-component-reference/guide/wave-selection-changed.html) - [Update](/docs/platform/lightning-component-reference/guide/wave-update.html) ## Experience Builder Events Customize Experience Builder site behavior using these events. - [Analytics Interaction](/docs/platform/lightning-component-reference/guide/forceCommunity-analytics-interaction.html) - [Analytics Interaction Gtag](/docs/platform/lightning-component-reference/guide/forceCommunity-analytics-interaction-gtag.html) - [Deflection Signal](/docs/platform/lightning-component-reference/guide/lightningcommunity-deflection-signal.html) - [Route Change](/docs/platform/lightning-component-reference/guide/forceCommunity-route-change.html) ## Navigation Events Navigate from a custom component to another page in Lightning Experience, Aura-based Experience Builder sites, and Salesforce mobile app. - [Navigate Home](/docs/platform/lightning-component-reference/guide/force-navigate-home.html) (Deprecated) - [Navigate To Component](/docs/platform/lightning-component-reference/guide/force-navigate-to-component.html) (Deprecated) - [Navigate To List](/docs/platform/lightning-component-reference/guide/force-navigate-to-list.html) (Beta) - [Navigate To Object Home](/docs/platform/lightning-component-reference/guide/force-navigate-to-object-home.html) - [Navigate To Related List](/docs/platform/lightning-component-reference/guide/force-navigate-to-related-list.html) (Beta) - [Navigate To SObject](/docs/platform/lightning-component-reference/guide/force-navigate-to-sobject.html) (Beta) - [Navigate To URL](/docs/platform/lightning-component-reference/guide/force-navigate-to-url.html) ## Page-Level Events Customize page-level behavior using these events. - [Close Quick Action](/docs/platform/lightning-component-reference/guide/force-close-quick-action.html) - [Refresh View](/docs/platform/lightning-component-reference/guide/force-refresh-view.html) - [Show Toast](/docs/platform/lightning-component-reference/guide/force-show-toast.html) ## Record Events Work with records using these events. - [Create Record](/docs/platform/lightning-component-reference/guide/force-create-record.html) - [Edit Record](/docs/platform/lightning-component-reference/guide/force-edit-record.html) - [Record Save](/docs/platform/lightning-component-reference/guide/force-record-save.html) - [Record Save Success](/docs/platform/lightning-component-reference/guide/force-record-save-success.html) - [Refresh View](/docs/platform/lightning-component-reference/guide/force-refresh-view.html) (Beta) ## See Also - [Events for Chat](https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_liveagent_events.htm) - [Events for Omni-Channel](https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_lightning_omnichannel_events.htm) - [Communicating with Events](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_intro.htm) # Aura Events in `aura` Namespace The `aura` namespace provides framework-level events that you can handle to customize component behavior. - [Application Event](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/applicationEvent/aura-application-event.md) - [Component Event](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/componentEvent/aura-component-event.md) - [Done Rendering (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/doneRendering/aura-done-rendering.md) - [Done Waiting (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/doneWaiting/aura-done-waiting.md) - [Location Change](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/locationChange/aura-location-change.md) - [Method Call](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/methodCall/aura-method-call.md) - [No Access](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/noAccess/aura-no-access.md) - [System Error](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/systemError/aura-system-error.md) - [Value Change](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/valueChange/aura-value-change.md) - [Value Destroy](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/valueDestroy/aura-value-destroy.md) - [Value Event](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/valueEvent/aura-value-event.md) - [Value Init](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/valueInit/aura-value-init.md) - [Value Render](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/valueRender/aura-value-render.md) - [Waiting (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/waiting/aura-waiting.md) # Aura Events in `force` Namespace The `force` namespace provides several events that you can fire to work with records and page navigation. - [Close Quick Action](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/closeQuickAction/force-close-quick-action.md) - [Create Record](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/createRecord/force-create-record.md) - [Edit Record](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/editRecord/force-edit-record.md) - [Navigate Home (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/navigateHome/force-navigate-home.md) - [Navigate To Component (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/navigateToComponent/force-navigate-to-component.md) - [Navigate To List (Beta)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/navigateToList/force-navigate-to-list.md) - [Navigate To Object Home](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/navigateToObjectHome/force-navigate-to-object-home.md) - [Navigate To Related List (Beta)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/navigateToRelatedList/force-navigate-to-related-list.md) - [Navigate To SObject (Beta)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/navigateToSObject/force-navigate-to-sobject.md) - [Navigate To URL](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/navigateToURL/force-navigate-to-url.md) - [Record Save](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/recordSave/force-record-save.md) - [Record Save Success](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/recordSaveSuccess/force-record-save-success.md) - [Refresh View (Beta)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/refreshView/force-refresh-view.md) - [Show Toast](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/showToast/force-show-toast.md) # Aura Events in `forceChatter` Namespace The `forceChatter` namespace provides several events. - [Custom Open File](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/customOpenFile/forceChatter-custom-open-file.md) - [Post Created](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/postCreated/forceChatter-post-created.md) # Aura Events in `forceCommunity` Namespace The `forceCommunity` namespace provides several events. - [Analytics Interaction](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/analyticsInteraction/forceCommunity-analytics-interaction.md) - [Analytics Interaction Gtag](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/analyticsInteractionGtag/forceCommunity-analytics-interaction-gtag.md) - [Route Change](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/routeChange/forceCommunity-route-change.md) # Aura Events in `lightning` Namespace The `lightning` namespace provides several Aura events to customize component behavior for Enhanced Messaging channels, Omni-Channel, and Lightning Console apps. - [Conversation Agent Send](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/conversationAgentSend/aura-conversation-agent-send.md) - [Conversation Chat Ended](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/conversationChatEnded/aura-conversation-chat-ended.md) - [Conversation Custom Event](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/conversationCustomEvent/aura-conversation-custom-event.md) - [Conversation New Message](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/conversationNewMessage/aura-conversation-new-message.md) - [Omni Channel Connection Error](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelConnectionError/aura-omni-channel-connection-error.md) - [Omni Channel Login Success](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelLoginSuccess/aura-omni-channel-login-success.md) - [Omni Channel Logout](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelLogout/aura-omni-channel-logout.md) - [Omni Channel Status Changed](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelStatusChanged/aura-omni-channel-status-changed.md) - [Omni Channel Work Accepted](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelWorkAccepted/aura-omni-channel-work-accepted.md) - [Omni Channel Work Assigned](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelWorkAssigned/aura-omni-channel-work-assigned.md) - [Omni Channel Work Closed](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelWorkClosed/aura-omni-channel-work-closed.md) - [Omni Channel Work Declined](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelWorkDeclined/aura-omni-channel-work-declined.md) - [Omni Channel Work Flag Updated](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelWorkFlagUpdated/aura-omni-channel-work-flag-updated.md) - [Omni Channel Workload Changed](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/omniChannelWorkloadChanged/aura-omni-channel-workload-changed.md) - [Open Files](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/openFiles/aura-open-files.md) - [Send Chatter Extension Payload](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/sendChatterExtensionPayload/aura-send-chatter-extension-payload.md) (Beta) - [Tab Closed](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/tabClosed/aura-tab-closed.md) - [Tab Created](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/tabCreated/aura-tab-created.md) - [Tab Focused](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/tabFocused/aura-tab-focused.md) - [Tab Refreshed](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/tabRefreshed/aura-tab-refreshed.md) - [Tab Replaced](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/tabReplaced/aura-tab-replaced.md) - [Tab Updated](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/tabUpdated/aura-tab-updated.md) # Aura Events in `lightningcommunity` Namespace The `lightningcommunity` namespace provides an event for working with Experience Builder Aura sites. - [Deflection Signal](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/deflectionSignal/lightningcommunity-deflection-signal.md) # Aura Events in `ltng` Namespace The `ltng` namespace provides several events. - [After Scripts Loaded](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/afterScriptsLoaded/ltng-after-scripts-loaded.md) - [Before Loading Resource](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/beforeLoadingResources/ltng-before-loading-resources.md) - [Select SObject](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/selectSObject/ltng-select-sobject.md) - [Send Message](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/sendMessage/ltng-send-message.md) # Aura Events in `ui` Namespace The `ui` namespace provides several events that you can use with [Aura components in the `ui` namespace](https://developer.salesforce.com/docs/platform/lightning-component-reference/aura-ui.md). - [Clear Error](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/clearErrors/ui-clear-errors.md) - [Collapse](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/collapse/ui-collapse.md) - [Expand](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/expand/ui-expand.md) - [Menu Focus Change (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/menuFocusChange/ui-menu-focus-change.md) - [Menu Select (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/menuSelect/ui-menu-select.md) - [Menu Trigger Press (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/menuTriggerPress/ui-menu-trigger-press.md) - [Validation Error (Deprecated)](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/validationError/ui-validation-error.md) # Aura Events in `wave` Namespace The `wave` namespace provides several events that you can use with [Aura components in the `wave` namespace](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/aura-wave-namespace.md). - [assetLoaded](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/assetLoaded/wave-asset-loaded.md) - [discover](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/discover/wave-discover.md) - [discoverResponse](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/discoverResponse/wave-discover-response.md) - [pageChange](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/pageChange/wave-page-change.md) - [selectionChanged](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/selectionChanged/wave-selection-changed.md) - [update](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/update/wave-update.md) # Aura Interfaces **note:** Use Lightning Web Components (LWC) where possible for new development. For more information, see [Migrate Interfaces](https://developer.salesforce.com/docs/platform/lwc/guide/migrate-interfaces.html). Aura Interfaces make your components available for use on record pages, flow screens, utility bars, and Aura-based Experience Builder sites. These interfaces enable you to integrate custom component logic with platform capabilities, allowing components to participate in declarative configuration and extend legacy Salesforce functionality. ## Marker Interfaces Marker interfaces enable a component to be used in a specific page or app, such as in Lightning App Builder, Experience Builder, and more. - [Action Override](/docs/platform/lightning-component-reference/guide/aura-action-override.html) - [Available For All Page Types](/docs/platform/lightning-component-reference/guide/flexipage-available-for-all-page-types.html) - [Available For Record Home](/docs/platform/lightning-component-reference/guide/flexipage-available-for-record-home.html) - [App Hostable](/docs/platform/lightning-component-reference/guide/force-app-hostable.html) - [Available for All Page Types](/docs/platform/lightning-component-reference/guide/forceCommunity-available-for-all-page-types.html) - [Available For Chatter Extension Composer](/docs/platform/lightning-component-reference/guide/aura-available-for-chatter-extension-composer.html) - [Available For Chatter Extension Renderer](/docs/platform/lightning-component-reference/guide/aura-available-for-chatter-extension-renderer.html) - [Available For Flow Actions](/docs/platform/lightning-component-reference/guide/aura-available-for-flow-actions.html) - [Available For Flow Screens](/docs/platform/lightning-component-reference/guide/aura-available-for-flow-screens.html) - [Available For Forecasting Page](/docs/platform/lightning-component-reference/guide/aura-available-for-forecasting-page.html) - [Available For Mail App App Page](/docs/platform/lightning-component-reference/guide/clients-available-for-mail-app-app-page.html) - [Background Utility Item](/docs/platform/lightning-component-reference/guide/aura-background-utility-item.html) - [Profile Menu Interface](/docs/platform/lightning-component-reference/guide/forceCommunity-profile-menu-interface.html) - [Search Interface](/docs/platform/lightning-component-reference/guide/forceCommunity-search-interface.html) - [Has Record Id](/docs/platform/lightning-component-reference/guide/force-has-record-id.html) - [Has SObject Name](/docs/platform/lightning-component-reference/guide/force-has-sobject-name.html) - [Lightning Quick Action](/docs/platform/lightning-component-reference/guide/force-lightning-quick-action.html) - [Lightning Quick Action Without Header](/docs/platform/lightning-component-reference/guide/force-lightning-quick-action-without-header.html) - [Utility Item](/docs/platform/lightning-component-reference/guide/aura-utility-item.html) ## Functional Interfaces Functional interfaces provide additional functionality to a component, such as enabling the component to be addressable directly via a URL. - [Allow In Relaxed CSP](/docs/platform/lightning-component-reference/guide/lightningcommunity-allow-in-relaxed-csp.html) - [Has Page Reference](/docs/platform/lightning-component-reference/guide/aura-has-page-reference.html) - [Is Url Addressable](/docs/platform/lightning-component-reference/guide/aura-is-url-addressable.html) - [Has Event Context](/docs/platform/lightning-component-reference/guide/clients-has-event-context.html) - [Has Item Context](/docs/platform/lightning-component-reference/guide/clients-has-item-context.html) ## Template Interfaces Template interfaces enable a component to be used as custom Lightning page templates in Lightning App Builder or Experience Builder. Each component can implement only one template interface and cannot implement other interfaces. - [App Home Template](/docs/platform/lightning-component-reference/guide/aura-app-home-template.html) - [Forecasting Template](/docs/platform/lightning-component-reference/guide/aura-forecasting-template.html) - [Home Template](/docs/platform/lightning-component-reference/guide/aura-home-template.html) - [Record Home Template](/docs/platform/lightning-component-reference/guide/aura-record-home-template.html) - [Layout](/docs/platform/lightning-component-reference/guide/forceCommunity-layout.html) - [Theme Layout](/docs/platform/lightning-component-reference/guide/forceCommunity-theme-layout.html) ## See Also [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/) # Aura Interfaces in `clients` Namespace The `clients` namespace provides these Aura interfaces. - [Available For Mail App App Page](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForMailAppAppPage/clients-available-for-mail-app-app-page.md) - [Has Event Context](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/hasEventContext/clients-has-event-context.md) - [Has Item Context](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/hasItemContext/clients-has-item-context.md) # Aura Interfaces in `flexipage` Namespace The `flexipage` namespace provides these Aura interfaces. - [Available For All Page Types](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForAllPageTypes/flexipage-available-for-all-page-types.md) - [Available For Record Home](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForRecordHome/flexipage-available-for-record-home.md) # Aura Interfaces in `force` Namespace The `force` namespace provides these Aura interfaces. - [App Hostable](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/appHostable/force-app-hostable.md) - [Has Record Id](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/hasRecordId/force-has-record-id.md) - [Has SObject Name](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/hasSObjectName/force-has-sobject-name.md) - [Lightning Quick Action](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightningQuickAction/force-lightning-quick-action.md) - [Lightning Quick Action Without Header](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/lightningQuickActionWithoutHeader/force-lightning-quick-action-without-header.md) # Aura Interfaces in `forceCommunity` Namespace The `forceCommunity` namespace provides these Aura interfaces. - [Available For All Page Types](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForAllPageTypes/forceCommunity-available-for-all-page-types.md) - [Layout](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/layout/forceCommunity-layout.md) - [Profile Menu Interface](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/profileMenuInterface/forceCommunity-profile-menu-interface.md) - [Search Interface](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/searchInterface/forceCommunity-search-interface.md) - [Theme Layout](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/themeLayout/forceCommunity-theme-layout.md) # Aura Interfaces in `lightning` Namespace The `lightning` namespace provides these Aura interfaces. - [Action Override](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/actionOverride/aura-action-override.md) - [App Home Template](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/appHomeTemplate/aura-app-home-template.md) - [Available For Chatter Extension Composer](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForChatterExtensionComposer/aura-available-for-chatter-extension-composer.md) - [Available For Chatter Extension Renderer](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForChatterExtensionRenderer/aura-available-for-chatter-extension-renderer.md) - [Available For Flow Actions](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForFlowActions/aura-available-for-flow-actions.md) - [Available For Flow Screens](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForFlowScreens/aura-available-for-flow-screens.md) - [Available For Forecasting Page](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/availableForForecastingPage/aura-available-for-forecasting-page.md) - [Background Utility Item](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/backgroundUtilityItem/aura-background-utility-item.md) - [Forecasting Template](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/forecastingTemplate/aura-forecasting-template.md) - [Has Page Reference](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/hasPageReference/aura-has-page-reference.md) - [Home Template](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/homeTemplate/aura-home-template.md) - [Is Url Addressable](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/isUrlAddressable/aura-is-url-addressable.md) - [Record Home Template](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/recordHomeTemplate/aura-record-home-template.md) - [Utility Item](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/utilityItem/aura-utility-item.md) # Aura Interfaces in `lightningcommunity` Namespace The `lightningcommunity` namespace provides this Aura interface. - [Allow In Relaxed CSP](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/allowInRelaxedCSP/lightningcommunity-allow-in-relaxed-csp.md) # Aura Interfaces in `ltng` Namespace The `ltng` namespace provides this Aura interface. - [Allow Guest Access](https://developer.salesforce.com/docs/platform/lightning-component-reference/guide/allowGuestAccess/ltng-allow-guest-access.md) # Available For All Page Types The `flexipage:availableForAllPageTypes` interface enables a component to be used on a page via the Lightning App Builder. **For Use In** Lightning Experience, Salesforce Mobile App ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab To make your component available for record pages and any other type of page, implement the `flexipage:availableForAllPageTypes` interface. If your component is designed for record pages only, use the [`flexipage:availableForRecordHome` interface](/docs/platform/lightning-component-reference/guide/flexipage-available-for-record-home.html) instead. Here's an example of a component that can be used in Lightning App Builder for a page. ```xml
{!v.greeting}, {!v.subject}!
``` For more information, see the [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder.htm). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For All Page Types **`forceCommunity:availableForAllPageTypes`** Enables a component for drag and drop in the Lightning Components panel in Experience Builder. ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab To appear in Experience Builder, a component must implement the `forceCommunity:availableForAllPageTypes` interface. Here's the sample code for a simple "Hello World" component. ```xml
{!v.greeting}, {!v.subject}!
``` Mark your resources, such as a component, with `access="global"` to make the resource usable outside of your own org. For example, if you want a component to be usable in an installed package or by a Lightning App Builder user or an Experience Builder user in another org. Next, add a design resource to your component bundle. A design resource describes the design-time behavior of an Aura component—information that visual tools need to allow adding the component to a page or app. It contains attributes that are available for administrators to edit in Experience Builder. ```xml ``` When you add custom components to your Experience Builder site, they can bypass the object- and field-level security (FLS) you set for the guest user profile. Aura components don’t automatically enforce CRUD and FLS when referencing objects or retrieving the objects from an Apex controller. This means that the framework continues to display records and fields for which users don’t have CRUD permissions and FLS visibility. You must manually enforce CRUD and FLS in your Apex controllers. For more information, see [Using Components](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_using_intro.htm?search_text=forceCommunity:availableForAllPageTypes) in the Lightning Aura Components Developer Guide. ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For Chatter Extension Composer **`lightning:availableForChatterExtensionComposer`** Enables a component to be used in the Chatter publisher. **For Use In** Experience Builder sites ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab Use the `lightning:availableForChatterExtensionComposer` interface to integrate your custom apps into the Chatter publisher and place the custom app’s payload in the feed. This interface is available in Experience Builder sites. The `lightning:availableForChatterExtensionComposer` interface works with the `lightning:availableForChatterExtensionRenderer` interface and the `lightning:sendChatterExtensionPayload` event to integrate your custom apps into the Chatter publisher and to render the app’s payload in the feed. For more information, see the [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_integrate_customapps_to_publisher.htm). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For Chatter Extension Renderer **`lightning:availableForChatterExtensionRenderer`** Enables a component to be used in the Chatter publisher. **For Use In** Experience Builder sites ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab Use the `lightning:availableForChatterExtensionRenderer` interface to integrate your custom apps into the Chatter publisher and place the custom app’s payload in the feed. This interface is available in Experience Builder sites. The `lightning:availableForChatterExtensionRenderer` interface works with the `lightning:availableForChatterExtensionComposer` interface and the `lightning:sendChatterExtensionPayload` event to integrate your custom apps into the Chatter publisher and to render the app’s payload in the feed. For more information, see the [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_integrate_customapps_to_publisher.htm). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For Flow Actions **`lightning:availableForFlowActions`** Enables a component's controller to be used as an action in a flow. **For Use In** Lightning Experience ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab Add the `lightning:availableForFlowActions` interface to a Lightning component to make it available as a flow action. When a component is executed as a flow action, the flow calls the `invoke` method in the client-side controller. Flows that include Lightning components are supported only in Lightning runtime. Lightning components that implement `lightning:availableForFlowActions` are available as Local Action elements in the Cloud Flow Designer. If an attribute is declared in the component's design resource, flow admins can pass values between that attribute and the flow when they configure the Local Action element. To run your code asynchronously, for example because you're making an XML HTTP request (XHR), return a Promise. When the method finishes or the Promise is settled, control is returned back to the flow. - Asynchronous Code: When a Promise is fulfilled, the next element in the flow is executed. When a Promise is rejected or times out, the flow takes the Local Action element's fault connector and sets `$Flow.FaultMessage` to the error message. By default, the error message is "An error occurred when the flow tried to execute the c:myComponent component.". To customize the error message, return it as an error in the `reject()` call. When a Promise times out, it returns control to the flow, but it doesn't cancel the original request. For example, if the request fires a `force:showToast` event after a delay, the event still fires even after the promise times out. To abort a Promise, use the `cancelToken` attribute provided by the interface. - Synchronous Code: When the method finishes, the next element in the flow is executed. This example shows the markup required to add the `lightning:availableForFlowActions` interface to a Lightning component. ```html // declare attributes here ``` Here's an example of an asynchronous client-side controller. The `invoke` method returns a Promise. When the method has done all it needs to do, it completes the call. If the request is successful, the method uses `resolve()` to execute the next element in the flow after this action. Otherwise, it uses `reject()` to take the Local Action element's fault connector and sets `$Flow.FaultMessage` to "My error message". If the request takes too long, it uses `cancelToken.promise.then` to abort the request. ```javascript /** Asynchronous Client-Side Controller **/ ({ invoke : function(component, event, helper) { var cancelToken = event.getParam("arguments").cancelToken; return new Promise(function(resolve, reject) { var xhttp = new XMLHttpRequest(); // Do something, like get data from // a database behind your firewall xhttp.onreadystatechange = $A.getCallback(function() { if (/* request was successful */) { // Complete the call and return to the flow resolve(); } else { reject(new Error("My error message")); } }); // Gracefully abort the Promise if it times out cancelToken.promise.then(function(error) { xhttp.abort(); reject(error); }); }); } }) ``` Here's an example of a synchronous client-side controller. When the `invoke` method finishes, control returns to the flow. ```javascript /** Synchronous Client-Side Controller **/ ({ invoke: function (component, event, helper) { // Do something, like open another browser tab // with a specified URL }, }); ``` For more information, see [Create Flow Actions By Using Lightning Components](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_flow_actions.htm). ## Methods This interface requires your component to implement the following method. `invoke(component, event, helper)`: Called when a flow executes the component as a local action. To handle asynchronous calls, construct a Promise in this method. - `cancelToken` (Object): A token that you can use to gracefully abort a Promise. When the Promise times out, `cancelToken.requested` is set to `true` and `cancelToken.promise` is resolved with a timeout Error object. ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For Flow Screens **`lightning:availableForFlowScreens`** Enables a component to be used in flow screens. **For Use In** Lightning Experience ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab Add the `lightning:availableForFlowScreens` interface to a Lightning component to make it available for flow screens. This interface is supported only in Lightning runtime. This example shows the markup required to add the `lightning:availableForFlowScreens` interface to a Lightning component. ```html ``` After making the component available to flow screens, you can add a resource bundle to enable attributes that admins can edit in the Cloud Flow Designer. You can also replace the whole flow screen with your own component. For more information, see the [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_flow_screens_intro.htm). ## Custom Validation Salesforce validates each flow screen when the user attempts to navigate to the next screen. If the flow screen is not valid, the user can’t progress. To validate the component with the flow screen, declare the `validate` attribute in the component. Set the `validate` attribute to a custom validation function that must return two parameters: `isValid` and `errorMessage`. Here's example markup for a Lightning component with custom validation. The `validate` attribute is set by the component’s client-side controller later in this example. ```html ``` Here's the corresponding client-side controller. When the component renders, the `init` handler sets the component's `validate` attribute to a function that validates the component. When the user navigates to the next flow screen, the function in the validate attribute is run. - If the component is valid, the function returns the `isValid` parameter as true and the user navigates to the next flow screen. - Otherwise, the function returns the `isValid` parameter as false and a custom error message that displays under the Lightning component in the flow screen. The user can't navigate to the next screen until the function is successful. ```javascript ({ init: function (cmp, event, helper) { // Set the validate attribute to a function that includes validation logic cmp.set("v.validate", function () { var userInput = cmp.get("v.textAttribute"); if (userInput && userInput.length > 0) { // If the component is valid... return { isValid: true }; } else { // If the component is invalid... return { isValid: false, errorMessage: "A value is required." }; } }); }, }); ``` ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For Forecasting Page **`lightning:availableForForecastingPage`** Enables a component to be used in a Lightning Forecasting page. **For Use In** Lightning Experience ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab Use the `lightning:availableForForecastingPage` interface to make your component available for Lightning Forecasting pages only. This example creates a "Hello World" component that's available only for Lightning Forecasting pages. ```
{!v.greeting}, {!v.subject}!
``` For more information, see [Configure Components for Lightning Pages and the Lightning App Builder](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder.htm) in the Lightning Aura Components Developer Guide. ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For Mail App App Page **`clients:availableForMailAppAppPage`** Enables components to show up in the Lightning for Gmail or Lightning For Outlook Flexipages. ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab To add a component to a Mail App Lightning page in the Lightning App Builder, or email application panes in Lightning for Outlook or Lightning for Gmail, implement the `clients:availableForMailAppAppPage` marker interface. This interface is used with `clients:hasItemContext` and `clients:hasEventContext`to implement record-specific and event-specific information. To ensure that custom components appear correctly in Lightning for Outlook or Lightning for Gmail, enable them to adjust to variable widths. For more information, see the [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder_email_app_pane.htm). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Available For Record Home The `flexipage:availableForRecordHome` interface enables a component to be used on a record home page via the Lightning App Builder. **For Use In** Lightning Experience, Salesforce Mobile App ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab To make your component available for record pages only, implement the `flexipage:availableForRecordHome` interface. If your component is designed for record pages and any other type of page, use the `flexipage:availableForAllPageTypes` interface instead. Here's an example of a component that can be used on a record page ```xml
{!v.greeting}, {!v.subject}!
``` For more information, see the [Lightning Aura Components Developer Guide](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_app_builder.htm). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Avatar **`lightning-avatar`** A visual representation of an object. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="avatar" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-avatar` component is an image that represents an object, such as an account or user. By default, the image renders in medium sizing with a rounded rectangle, which is also known as the `square` variant. Here’s a basic avatar example. ```html ``` To use an image in your org as an avatar, upload the image as a static resource in the Static Resources setup page. Import the image from the [`@salesforce/resourceUrl` module](https://developer.salesforce.com/docs/platform/lwc/guide/create-resources.html) and use it in the `src` attribute. ## Design `lightning-avatar` implements the avatar blueprint in the Salesforce Lightning Design System (SLDS). The avatar adapts to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Avatar](https://v1.lightningdesignsystem.com/components/avatar/) | [Avatar](https://www.lightningdesignsystem.com/components/avatar/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Handle Invalid Image Paths The `src` attribute resolves the relative path to an image, but sometimes the image path doesn't resolve correctly because the user is offline or the image has been deleted. To handle an invalid image path, you can provide fallback initials by using the `initials` attribute or a fallback icon with the `fallback-icon-name` attribute. These attributes work together if both are specified. If initials and fallback icon name are provided, the initials are shown and the background color of the fallback icon is used as the background color for the initials. The fallback icon is shown only when the image path is invalid and initials aren’t provided. This example shows the initials "Sa" if the image path is invalid. The fallback icon "standard:account" provides the background color for the initials. The icon is one of the [standard icons](https://v1.lightningdesignsystem.com/icons/#standard) in SLDS. ```html ``` ## Component Styling Use a combination of icons, variants, and utility classes to style your avatars. ### Icons Although SLDS provides several categories of icons, only icons from the [standard](https://v1.lightningdesignsystem.com/icons/#standard) and [custom](https://v1.lightningdesignsystem.com/icons/#custom) categories can be used in `lightning-avatar`. **note:** When applying SLDS classes or icons, check that they’re available in the SLDS release tied to your org. The latest SLDS resources become available only when the new release is available in your org. ### Variants Use the `variant` attribute with one of these values to apply styling. - `square` is the default variant, displaying a rectangle avatar with rounded corners - `circle` displays a round avatar This example creates a round avatar. ```html ``` ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds a margin around the avatar using an SLDS class. The fallback icon is displayed if the image path is invalid. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Accessibility Use the `alternative-text` attribute to describe the avatar, such as a user's initials or name. This description provides the value for the `alt` attribute in the `img` HTML tag. ::::: :::::tab ::component-specification{component="avatar" model="lwc" namespace="lightning"} ::::: :::::: # Background Utility Item **`lightning:backgroundUtilityItem`** Enables a component to be used at the app level without rendering any UI. **For Use In** Lightning Experience ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab Implement the `lightning:backgroundUtilityItem` interface to allow a component to be used as an app-level component that is created when the app loads, and runs code without rendering itself in the app UI. Components that implement this interface are added to the app through the Select Utility Items milestone in Setup. This example shows how to implement a background utility item that listens for `lightning:tabCreated` events when the app loads, and invokes `lightning:workspaceAPI` methods to prevent more than 10 tabs from opening. ```html ``` In your client-side controller, limit the number of tabs when a new tab is created. ```javascript ({ onTabCreated: function (cmp) { var workspace = cmp.find("workspace"); workspace.getAllTabInfo().then(function (tabInfo) { if (tabInfo.length > 10) { workspace.closeTab({ tabId: tabInfo[0].tabId, }); } }); }, }); ``` ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Badge **`lightning-badge`** Represents a label which holds a small amount of information, such as the number of unread notifications. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="badge" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-badge` component is a label that holds small amounts of information. A badge can show the status of unread notifications, or provide a label for a block of text. Badges don't work for navigation because they can't include a hyperlink. You can create two types of badges. - A text-only badge - A badge with an icon that appears before or after the text Here’s an example of a text-only badge. ```html ``` To create a badge with an icon, set the `icon-name` to a Lightning Design System icon. The icon appears before the text by default. ```html ``` To place the icon after the text, set `icon-position="end"`. ```html ``` ## Design `lightning-badge` implements the badge blueprint in the Salesforce Lightning Design System (SLDS). The badge adapts to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Badge](https://v1.lightningdesignsystem.com/components/badges/) | [Badge](https://www.lightningdesignsystem.com/components/badges/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Component Styling Use a combination of icons and utility classes to style your badges. ### Icons See the [SLDS icons](https://v1.lightningdesignsystem.com/icons) for available icons. **note:** When applying SLDS classes or icons, check that they’re available in the SLDS release tied to your org. The latest SLDS resources become available only when the new release is available in your org. ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. Change the badge color by using an SLDS class. See [colors](https://v1.lightningdesignsystem.com/components/badges/#Colors) for more information. This example creates a green badge by using the `slds-theme_success` SLDS class. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Usage Considerations Badges with nested elements are not supported. To create a label that contains links, use [`lightning-pill`](/docs/platform/lightning-component-reference/guide/lightning-pill.html) instead. ::::: :::::tab ::component-specification{component="badge" model="lwc" namespace="lightning"} ::::: :::::: # Barcode Scanner **`lightning-barcode-scanner`** Scans barcodes on a mobile device. **For Use In** Salesforce Mobile App ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab The `lightning-barcode-scanner` component embeds a barcode scanning function displayed as an icon, which launches the barcode scanner when the user clicks it. For more information on the API this component uses, see [Use the BarcodeScanner API](https://developer.salesforce.com/docs/platform/lwc/guide/reference-lightning-barcodescanner.html) in the Lightning Web Components Developer Guide. ```html ``` To disable the barcode scanner, set the `disabled` attribute. The barcode scanner is enabled by default. ```html ``` ## Scanning Modes Barcode scanning supports both single scan and continuous scan. A single scan component automatically closes after one successful scan, while a continuous scan component remains open. The `lightning-barcode-scanner` component is single scan by default. To enable continuous scanning, set the `enable-continuous-scan` attribute. ```html ``` ## Scanner Options The BarcodeScanner API for `lightning-barcode-scanner` supports various scanner options. For the list of barcode scanner option properties, see [BarcodeScannerOptions](https://developer.salesforce.com/docs/platform/lwc/guide/reference-lightning-barcodescanner-data-types) in the Lightning Web Components Developer Guide. You can configure various scanner options for a scanning session. For example, if you want your component to support only a specific set of barcode types, specify the types as a list in the `barcodeTypes` property. If you want to modify the size of the scanner camera view, specify the size in the `scannerSize` property. In this example, the barcode scanner supports only the specified types `CODE_128`,`EAN_13`, and `QR`, and will ignore the other types, and the barcode scanner camera view is changed to `LARGE`. ```html ``` ```javascript const myScannerOptions = { barcodeTypes: ["CODE_128", "QR", "EAN_13"], scannerSize: "LARGE", }; ``` ## Icons To specify an icon size for the barcode scanner component, set the `icon-size` attribute. By default, the `icon-size` is medium. ```html ``` To set custom assistive technology text for the component icon in its enabled and disabled state, set the `enabled-alternative-text` and `disabled-alternative-text` attributes. ```html ``` You can also create a custom icon for the component by specifying images and alternative texts to use in the component's enabled and disabled states. To use a custom image for the barcode scanner icon, set the `enabled-icon-src` and `disabled-icon-src` attributes to image paths in the `staticResource` folder. This example uses custom image for the component's icon enabled and disabled states. ```html ``` ## Custom Events The `lightning-barcode-scanner` component supports two events, `scan` and `error`. The `scan` event is triggered by a successful scan on a single scan component or by successfully closing the scanner window on a multiple scan component. It returns this parameter. | Parameter | Type | Description | | --------------- | ---- | ------------------------------------- | | scannedBarcodes | list | Returns an array of scanned barcodes. | The `scan` event has these properties. | Property | Value | Description | | ---------- | ----- | ------------------------------------------------------------------------------------------------------------ | | bubbles | false | This event does not bubble. | | cancelable | true | This event can be canceled. You can call `preventDefault()` on this event to prevent firing the click event. | | composed | false | This event does not propagate outside the template in which it was dispatched. | The `errors` event is triggered if there is an error during the scan. The event contains the error details. It returns this parameter. | Parameter | Type | Description | | --------- | ------ | -------------------------- | | error | object | Returns the error details. | The `errors` event has these properties. | Property | Value | Description | | ---------- | ----- | ------------------------------------------------------------------------------------------------------------ | | bubbles | false | This event does not bubble. | | cancelable | true | This event can be canceled. You can call `preventDefault()` on this event to prevent firing the click event. | | composed | false | This event does not propagate outside the template in which it was dispatched. | ::::: :::::tab ::component-specification{component="barcodeScanner" model="lwc" namespace="lightning"} ::::: :::::: # Before Loading Resources **`ltng:beforeLoadingResources`** Fired before [`ltng:require`](/docs/platform/lightning-component-reference/guide/ltng-require.html) attempts to load the requested resources. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App ::::::tabset{tabs='["Develop", "Specifications"]'} :::::tab For more information, see the [`ltng:require` documentation](/docs/platform/lightning-component-reference/guide/ltng-require.html). ::::: :::::tab ![No specifications to show](https://developer.salesforce.com/media/no-specs.png) ::::: :::::: # Breadcrumb **`lightning-breadcrumb`** An item in the hierarchy path of the page the user is on. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='[ "Develop", "Specifications"]'} :::::tab A `lightning-breadcrumb` component shows the path of a page relative to a parent page. Nest `lightning-breadcrumb` in a `lightning-breadcrumbs` component. Each breadcrumb is actionable and separated by a greater-than sign. The order the breadcrumbs appear depends on the order they’re listed in markup. Here's an example. ```html ``` ## Design Use `lightning-breadcrumb` within [`lightning-breadcrumbs`](/docs/platform/lightning-component-reference/guide/lightning-breadcrumbs.html), which implements the breadcrumbs blueprint in the Salesforce Lightning Design System (SLDS). The breadcrumbs adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Breadcrumbs](https://v1.lightningdesignsystem.com/components/breadcrumbs/) | [Breadcrumbs](https://www.lightningdesignsystem.com/components/breadcrumb/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Create Links Using Breadcrumbs The behavior of a breadcrumb is similar to a link that's for navigation. If a link isn’t provided via the `href` attribute, the value defaults to `#`. Since a breadcrumb is for navigation, we don't recommend leaving out the `href` attribute because `#` links to the same page when middle-clicked or opened in a new tab. To provide custom navigation, use an `onclick` handler with [`lightning-navigation`](/docs/platform/lightning-component-reference/guide/lightning-navigation.html). If you provide a link in the `href` attribute, calling `event.preventDefault()` enables you to bypass the link and use your custom navigation instead. ```html ``` Handle the `click` events in your JavaScript code. ```javascript import { LightningElement } from 'lwc'; export default class DemoBreadcrumbs extends LightningElement { handleNavigateToCustomPage1(event) { event.preventDefault(); //your custom navigation here } handleNavigateToCustomPage2(event) { event.preventDefault(); //your custom navigation here } ``` ## Generate Breadcrumbs with Iteration Iterate over a list of items by using `for:each` to generate breadcrumbs. If you don't provide a link with an `onclick` handler, `href` defaults to `#`. For example, you can create an array of breadcrumbs with label and name values. ```html ``` Get the name of the breadcrumb that's clicked by using the `event.target` property. ```javascript //mybreadcrumbs.js import { LightningElement, track } from "lwc"; export default class MyComponentName extends LightningElement { @track myBreadcrumbs = [ { label: "Account", name: "objectName", id: "account1" }, { label: "Record Name", name: "record", id: "account2" }, ]; handleNavigateTo(event) { //get the name of the breadcrumb that's clicked const name = event.target.name; event.preventDefault(); //your custom navigation here } } ``` ## Usage Considerations A breadcrumb shows your location in an app's hierarchy, not your browsing history. Breadcrumbs are especially useful when you want to go to a parent page from another page in the app. They also help you situate yourself in the app. Breadcrumbs are commonly used with a tree for navigating between nested pages. The full hierarchy path is listed on a second or third level page. Creating breadcrumbs with an overflow menu using `lightning-breadcrumbs` isn't currently supported. ## See Also [`lightning-navigation`](/docs/platform/lightning-component-reference/guide/lightning-navigation.html) ::::: :::::tab ::component-specification{component="breadcrumb" model="lwc" namespace="lightning"} ::::: :::::: # Breadcrumbs **`lightning-breadcrumbs`** A hierarchy path of the page you're currently visiting within the website or app. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="breadcrumbs" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-breadcrumbs` component is an ordered list that shows the path of a page and helps you navigate back to the parent. Each breadcrumb item is a `lightning-breadcrumb` component. Breadcrumbs are actionable and separated by a greater-than sign. For more information, see the [`lightning-breadcrumb`](/docs/platform/lightning-component-reference/guide/lightning-breadcrumb.html) documentation. ## Design `lightning-breadcrumbs` implements the breadcrumbs blueprint in the Salesforce Lightning Design System (SLDS). The breadcrumbs adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Breadcrumbs](https://v1.lightningdesignsystem.com/components/breadcrumbs/) | [Breadcrumbs](https://www.lightningdesignsystem.com/components/breadcrumb/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Component Styling Use utility classes to style your breadcrumbs. ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds a margin around the breadcrumbs using an SLDS class. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Accessibility `lightning-breadcrumbs` renders with `role="navigation"`, which is a landmark role that enables screen readers to provide keyboard navigation to the links on the breadcrumbs. The `aria-label="Breadcrumbs"` property is rendered automatically to inform screen readers the navigation type. Screen readers read both the role and the label description. If your page includes another navigation landmark besides the breadcrumbs, you can use a different label for the other navigation landmark. Updating the `aria-label` property on `lightning-breadcrumbs` is currently not supported. The last breadcrumb item usually corresponds to the current page that a user is viewing. This breadcrumb item renders with `aria-current="page"`, which is announced by the screen reader as the current page within a set of navigation links. ::::: :::::tab ::component-specification{component="breadcrumbs" model="lwc" namespace="lightning"} ::::: :::::: # Button **`lightning-button`** A clickable element used to perform an action. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="button" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-button` component represents a button element that runs an action. Use `lightning-button` to: - Submit or reset a form - Begin a new task - Trigger a new UI element to appear on the page - Specify a new or next step in a process Use the `type` attribute to specify `button`, `submit`, or `reset`. The default type is `button`. The `submit` and `reset` types create buttons for submitting and resetting form data. Use these button types in `lightning-record-edit-form` and the HTML `form` element. The `reset` type button only deletes the values in the form fields without interacting with the database. For information about resetting the form fields to their initial values, see [`lightning-record-edit-form`](/docs/platform/lightning-component-reference/guide/lightning-record-edit-form.html). For the default button, clicking the button triggers the `click` event. Use an `onclick` handler to perform the button's action. You can create a button with a label only, or add the `icon-name` attribute for a button with a label and icon. To create an icon-only button, use the `lightning-button-icon` component instead. Here's an example that creates a button with the `brand` variant, and shows `label` text on the button. The `title` attribute provides tooltip text for the button. ```html ``` Here's another example that creates a button with the `brand` variant, with a label and icon. The button places the icon to the left of the label by default, so the example uses `icon-position` to place the icon on the right. ```html ``` You can retrieve the label of the button that's clicked by using `event.target`. For example, to retrieve the label on the button, use `event.target.label`. You can also use the `stretch` attribute to expand the button to the full available width. In this example, the button stretches horizontally to fit the full `
` container. ```html
``` ## Design `lightning-button` implements the buttons blueprint in the Salesforce Lightning Design System (SLDS). The buttons adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Buttons](https://v1.lightningdesignsystem.com/components/buttons/) | [Buttons](https://www.lightningdesignsystem.com/components/buttons/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Component Styling Use a combination of icons, variants, and utility classes to customize your button styles. ### Icons Use the `icon-name` attribute to add a utility icon to the button. The [SLDS utility icon category](https://v1.lightningdesignsystem.com/icons/#utility) provides nearly 200 utility icons that can be used in `lightning-button` along with label text. Although SLDS provides several categories of icons, only the utility category can be used in `lightning-button`. ### Variants Use the `variant` attribute with one of these values to apply styling and animation. - `base` is a button without a border, which gives it the look of a plain text link. - `neutral` is the default variant, a plain uncolored button. - `brand` is a blue button, used to draw attention to the primary action on a page. - `brand-outline` is similar to `brand` but the color is used for the label and border only, not the button color. - `destructive` is a red button used to warn users that its action has a negative effect. - `destructive-text` is similar to `destructive` but only the label and border are red. - `inverse` uses the background color and light text, useful for dark backgrounds. - `success` is a green button used to indicate a successful action. ### Animation Buttons are animated by default. For the `base` variant, an underline is drawn when you mouse over the button. For the other variants, a ripple of contrasting color appears when you click the button. When a button is disabled, the animation is disabled as well. If your browser or operating system is set to reduce animation, the button animations don't appear. To prevent animation for a button, use the `disable-animation` attribute. ```html ``` We recommend setting this attribute only when you place `lightning-button` near other buttons that aren't animated, for consistency. ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds a margin to the left of the second button by using an SLDS class. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. `lightning-button` supports these component styling hooks. | CSS Custom Property | `lightning-button` Variants | | ------------------------------------ | ------------------------------------------------ | | `--slds-c-button-*` | all | | `--slds-c-button-color-*` | `base` | | `--slds-c-button-text-color-*` | `neutral` (default), `base`, and `brand-outline` | | `--slds-c-button-neutral-*` | `neutral` (default) | | `--slds-c-button-brand-*` | `brand` | | `--slds-c-button-outline-brand-*` | `brand-outline` | | `--slds-c-button-destructive-*` | `destructive` | | `--slds-c-button-text-destructive-*` | `destructive-text` | | `--slds-c-button-inverse-*` | `inverse` | | `--slds-c-button-success-*` | `success` | ## Usage Considerations To create an icon-only button, use the `lightning-button-icon` component instead. Creating an icon-only button by using `lightning-button` results in additional spacing next to the icon. To create a button that triggers a menu, use `lightning-button-menu`. Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences. If you're creating forms to interact with Salesforce records, consider `lightning-record-form` or `lightning-record-edit-form` instead of creating your own. On mobile screens, we recommend setting the button size to 44x44 px. If you have more than one target on a screen that performs the same action, only one of the targets needs to meet the target size of 44x44 px. For more information, see [Follow Accessible Mobile Design Guidelines](https://developer.salesforce.com/docs/platform/lwc/guide/mobile-a11y). ## Accessibility Buttons must have an accessible name for assistive technology to announce the button's purpose. Provide this name by using the `label` attribute and make it a clear call to action, for example, "Edit record". If you create an icon-only button with `lightning-button`, provide an accessible name by using the `aria-label` or `aria-labelledby` attribute. We recommend that you use one of the attributes but not both. To provide a text label that's not visible on the screen, use `aria-label`. ```html ``` To associate the button with text from another element, use `aria-labelledby`. ```html

Download Files

View and make changes to your files

``` To use `aria-label` with additional descriptive text, use `aria-describedby`. ```html
Closing this window resets the form and returns you back to the main page.
``` `lightning-button` provides many variants that add color to a button, which convey different meaning on a button. Use the variants together with clear text on the button to match the meaning you’re trying to convey via color. For example, if you use the destructive button to point out a potential warning, make sure that the text communicates the same message. To inform screen readers that a button is disabled, include the `disabled` attribute. Use these accessibility and `aria` attributes on `lightning-button`. | Attribute | Type | Description | | ---------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | accesskey | string | A shortcut key to activate or place focus on the button. | | aria-atomic | boolean | Specifies whether the screen reader should always present the live region as a whole, even if only part of the region changes. The default is `false`. | | aria-controls | ID reference list | An element ID or a space-separated list of element IDs whose presence or content is controlled by this button. | | aria-describedby | ID reference list | An element ID or a space-separated list of element IDs that provide a descriptive label or description for the button. | | aria-expanded | boolean | Indicates whether a collapsible element that's controlled by the button is expanded or collapsed. To reference the controlled element, use `aria-controls`. | | aria-haspopup | token | Indicates that the button has an interactive popup element. Valid values are 'true', 'dialog', 'menu', 'listbox', 'tree', and 'grid'. | | aria-label | string | Provides an assistive label where a visible label can’t be used. | | aria-labelledby | ID reference list | Specifies the ID or list of IDs of the element or elements that contain visible descriptive text to describe the button. | | aria-live | token | Indicates that the button can dynamically update without a page reload, and specifies how the change is announced by assistive technologies. Possible values include `off`, `polite`, and `assertive`. The default is `off`. For the screen reader to announce changes when the user is idle, use `polite`. For immediate notifications, use `assertive`. | | tabindex | integer | Specifies whether the button is focusable during tab navigation. Set the tab index to -1 to prevent focus on the button during tab navigation. The default value is 0, which makes the button focusable during tab navigation. For more information, see [tabindex](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex). | For more information, see the [WAI-ARIA Specification](https://www.w3.org/TR/wai-aria/). ::::: :::::tab ::component-specification{component="button" model="lwc" namespace="lightning"} ::::: :::::: # Button Group **`lightning-button-group`** Represents a group of buttons. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="buttonGroup" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-button-group` component represents a set of buttons that appear together to create a navigational bar. The body of the component can contain one or more of these components: - [`lightning-button`](/docs/platform/lightning-component-reference/guide/lightning-button.html) - [`lightning-button-icon`](/docs/platform/lightning-component-reference/guide/lightning-button-icon.html) - [`lightning-button-icon-stateful`](/docs/platform/lightning-component-reference/guide/lightning-button-icon-stateful.html) - [`lightning-button-menu`](/docs/platform/lightning-component-reference/guide/lightning-button-menu.html) - [`lightning-button-stateful`](/docs/platform/lightning-component-reference/guide/lightning-button-stateful.html) To create navigational tabs, use [`lightning-tabset`](/docs/platform/lightning-component-reference/guide/lightning-tabset.html) instead of `lightning-button-group`. When you use `lightning-button-menu`, set `variant="border-filled"` on the button menu for a white button background. Otherwise, the `lightning-button-menu` background is transparent by default. To create buttons, use the `lightning-button` component as shown in this example. ```html ``` Handle clicks by using the `onclick` handler. ```html ``` In your JavaScript code, use the `event.target` property to retrieve the label of the clicked button. ```javascript import { LightningElement } from "lwc"; export default class DemoApp extends LightningElement { handleClick(event) { const buttonLabel = event.target.label; // Handle clicks } } ``` To handle navigation within Lightning Experience and the Salesforce app, use the [`lightning-navigation`](/docs/platform/lightning-component-reference/guide/lightning-navigation.html) component. ## Design `lightning-button-group` implements the button groups blueprint in the Salesforce Lightning Design System (SLDS). The button groups adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Button Groups](https://v1.lightningdesignsystem.com/components/button-groups/) | [Button Groups](https://www.lightningdesignsystem.com/components/button-groups/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Component Styling To apply additional styling, use SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. You can customize the `lightning-button-*` base components you use within `lightning-button-group` by using SLDS styling hooks. For more information, see the corresponding base component documentation. ## See Also [lightning-navigation](/docs/platform/lightning-component-reference/guide/lightning-navigation.html) [Navigate to Pages](https://developer.salesforce.com/docs/platform/lwc/guide/use-navigate) ::::: :::::tab ::component-specification{component="buttonGroup" model="lwc" namespace="lightning"} ::::: :::::: # Button Icon **`lightning-button-icon`** A button that contains only an icon. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="buttonIcon" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-button-icon` component represents an icon-only button element that runs an action. Clicking the button triggers the JavaScript method set for `onclick`. Here’s an example. ```html ``` ## Design `lightning-button-icon` implements the button icons blueprint in the Salesforce Lightning Design System (SLDS). The button icons adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Button Icons](https://v1.lightningdesignsystem.com/components/button-icons/) | [Button Icons](https://www.lightningdesignsystem.com/components/button-icons/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Component Styling Use a combination of the `icon-class`, `size`, `variant`, and `class` attributes to customize the button and icon styles. To customize styling on the icon element, use the `icon-class` attribute. This example creates an icon-only button with bare variant and icon styling. `icon-class` supports SLDS utility classes only. ```html ``` ### Icons Use the `icon-name` attribute to add a utility icon to the button. The [SLDS utility icon category](https://v1.lightningdesignsystem.com/icons/#utility) offers nearly 200 utility icons for use with `lightning-button-icon`. You can use only the utility category with `lightning-button-icon`. **note:** When applying SLDS classes or icons, check that they’re available in the SLDS release tied to your org. The latest SLDS resources become available only when the new release is available in your org. ### Variants Use the `variant` attribute with one of these values to apply styling. - `bare` shows an icon without a container or border - `bare-inverse` shows an icon in white color without a container or border, useful for dark backgrounds - `border` is the default variant, an icon in a transparent container with a border - `border-filled` shows an icon in a filled container with a border - `border-inverse` shows an icon in a transparent container with a border, useful for dark backgrounds - `brand` shows an icon in white color in a blue container with a blue border - `container` shows an icon in a transparent container without a border For the `bare` and `bare-inverse` variants, the `size` class applies to the icon itself. For all other variants, the `size` class applies to the button. Add the `disabled` attribute to prevent interaction with the button icon. ### Sizes Adjust the button and icon sizes by using the `size` attribute with one of these values. For `bare` and `bare-inverse` variants: - `medium` is the default size, which creates a 14px by 14px icon - `small` creates a 12px by 12px icon - `x-small` creates a 8px by 8px icon - `large` creates a 24px by 24px icon For other variants: - `medium` is the default size, which creates a 32px by 32px button enclosing a 14px by 14px icon. - `small` creates a 24px by 24px button enclosing a 14px by 14px icon - `x-small` creates a 20px by 20px button enclosing a 12px by 12px icon - `xx-small` creates a 16px by 16px button enclosing a 8px by 8px icon ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds a margin to the left of the second button by using the `slds-m-left_xx-small` class. ```html ``` To apply custom styling, use the `:host` selector or define a custom class by using the `class` attribute. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. `lightning-button-icon` contains the same customizable elements as `lightning-button`, which supports `--slds-c-button-*` custom properties. Custom properties for button icons work only with specific `lightning-button-icon` variants. | CSS Custom Property | `lightning-button-icon` Variants | | ---------------------------------- | ------------------------------------------------------------ | | `--slds-c-button-color-background` | `border` (default), `bare`, `bare-inverse`, and `container` | | `--slds-c-button-color-border` | `bare`, `bare-inverse`, and `container` | | `--slds-c-button-text-color` | N/A | | `--slds-c-button-text-color-*` | `border` (default), `bare`, `container`, and `border-filled` | | `--slds-c-button-radius-border` | all | | `--slds-c-button-sizing-border` | `bare`, `bare-inverse`, `border-inverse`, and `container` | For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Usage Considerations Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences. ## Accessibility `lightning-button-icon` contains an informational icon, which conveys information that surrounding text doesn't. For each icon, provide assistive text that describes the button's action. Use the `alternative-text` attribute to describe the icon. The description indicates what happens when you click the button, for example 'Upload File', not what the icon looks like, 'Paperclip'. The description you provide to `alternative-text` is available to users in two ways. - As hover text when you hover over the button - As hidden text for assistive technologies To override the hover text provided by `alternative-text`, use the `title` attribute, which corresponds to the native browser tooltip. The description you provide to `title` appears when you hover over the button. To support touch-only devices, keyboard navigation, and assistive technologies, use `title` together with `label` or `alternative-text`. To show a contextual popup on the button, use the `tooltip` attribute. The popup becomes visible when you hover over the button, or after the button receives keyboard focus. Showing the popup on hover or on keyboard focus makes sure that all users can access it, even if they aren’t using a mouse. The button is rendered with `aria-describedby`, linking it to the ID of the popup, which helps assistive technology read the popup content. If you use both `title` and `tooltip` attributes, they’re both visible when you hover over the button. Some screen readers don’t support the `title` attribute and many of them don’t read the `title` attribute by default. ```html ``` For sighted users, make sure your description on `title` and `tooltip` aren’t repetitive. We recommend providing detailed information to `tooltip` and make `title` more concise if you use both. Buttons that show an icon instead of text don’t have an accessible name. To provide an accessible name in `lightning-button-icon`, use the `aria-label` attribute. If there’s visible text for the element, use `aria-labelled-by` instead. To inform screen readers that a button is disabled, set the `disabled` attribute to true. Use these accessibility and `aria` attributes on `lightning-button-icon`. | Attribute | Type | Description | | ---------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | accesskey | string | A shortcut key to activate or place focus on the button. | | aria-atomic | boolean | Specifies whether the screen reader always presents the live region as a whole, even if only part of the region changes. The default is `false`. | | aria-controls | ID reference list | An element ID or a space-separated list of element IDs whose presence or content is controlled by this button. | | aria-describedby | ID reference list | An element ID or a space-separated list of element IDs that provide descriptive labels for the button. | | aria-expanded | boolean | Indicates whether a collapsible element that's controlled by the button is expanded or collapsed. To reference the controlled element, use `aria-controls`. | | aria-haspopup | token | Indicates that the button has an interactive popup element. Valid values are 'true', 'dialog', 'menu', 'listbox', 'tree', and 'grid'. To create a button that displays a list of menu items when clicked, use `lightning-button-menu` instead. | | aria-label | string | Provides an assistive label where a visible label can’t be used. | | aria-live | token | Indicates that the button can dynamically update without a page reload, and specifies how the change is announced by assistive technologies. Possible values include `off`, `polite`, and `assertive`. The default is `off`. For the screen reader to announce changes when the user is idle, use `polite`. For immediate notifications, use `assertive`. | | tabindex | integer | Specifies whether the button is focusable during tab navigation. Set the tab index to -1 to prevent focus on the button during tab navigation. The default value is 0, which makes the button focusable during tab navigation. For more information, see [tabindex](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex). | For more information, see the [WAI-ARIA Specification](https://www.w3.org/TR/wai-aria/). ::::: :::::tab ::component-specification{component="buttonIcon" model="lwc" namespace="lightning"} ::::: :::::: # Button Icon Stateful **`lightning-button-icon-stateful`** An icon-only button that retains state. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="buttonIconStateful" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-button-icon-stateful` component represents an icon-only button element that toggles between two states. For example, you can use this component for capturing a customer's feedback on a blog post (like or dislike). Clicking the button triggers the handler set for `onclick`. You can change the state of the icon by using the `selected` attribute. This example creates a Like button that toggles between two states. The Like button is selected by default. The button's state is stored in the `selected` attribute. Selecting the Dislike button also toggles the state on the Like button and deselects it. ```html ``` Handle the `click` event in your JavaScript code. ```javascript import { LightningElement } from "lwc"; export default class MyComponentName extends LightningElement { liked = true; handleToggle() { this.liked = !this.liked; } } ``` ## Design `lightning-button-icon-stateful` implements the button icons blueprint in the Salesforce Lightning Design System (SLDS). The button icons adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Button Icons (Stateful)](https://v1.lightningdesignsystem.com/components/button-icons/#Stateful) | [Button Icons](https://www.lightningdesignsystem.com/components/button-icons/#Stateful) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Component Styling Use a combination of `icon-name`, `variant`, `size`, and `class` attributes to customize the button and icon styles. ### Icons Use the `icon-name` attribute to add a utility icon to the button. The [SLDS utility icon category](https://v1.lightningdesignsystem.com/icons/#utility) offers nearly 200 utility icons that can be used in `lightning-button-icon-stateful`. Although the SLDS provides several categories of icons, only the utility category can be used with this component. **note:** When applying SLDS classes or icons, check that they are available in the SLDS release tied to your org. The latest SLDS resources become available only when the new release is available in your org. ### Variants Use the `variant` attribute with one of these values to apply styling. - `border` is the default variant, an icon in a transparent container with a border - `border-filled` shows an icon in a filled container with a border - `border-inverse` shows an icon in a transparent container with a border, useful for dark backgrounds ### Sizes Adjust the button and icon sizes by using the `size` attribute with one of these values. - `medium` is the default size, which creates a 32px by 32px button enclosing a 14px by 14px icon. - `small` creates a 24px by 24px button enclosing a 14px by 14px icon - `x-small` creates a 20px by 20px button enclosing a 12px by 12px icon - `xx-small` creates a 16px by 16px button enclosing a 8px by 8px icon ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds a margin to the left of the second button by using an SLDS class. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. CSS custom properties for stateful button icons work only with specific `lightning-button-icon-stateful` variants. | CSS Custom Property | `lightning-button-icon-stateful` Variants | | ---------------------------------- | ----------------------------------------- | | `--slds-c-button-color-background` | `border` (default) and `border-inverse` | | `--slds-c-button-color-border` | N/A | | `--slds-c-button-text-color` | N/A | | `--slds-c-button-text-color-*` | `border` (default) and `border-filled` | | `--slds-c-button-radius-border` | all | | `--slds-c-button-sizing-border` | N/A | For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Usage Considerations Icons are not available in Lightning Out, but they are available in Lightning Components for Visualforce and other experiences. ## Accessibility `lightning-button-icon-stateful` contains an informational icon, which conveys information that surrounding text doesn't. Each icon should be accompanied by either assistive text. When selected, the button renders with `aria-pressed="true"`. When not selected, the button renders with `aria-pressed="false"`. The `aria-pressed` attribute enables screen readers to announce whether a button is pressed or not. Use the `alternative-text` attribute to describe the icon. The description should indicate what happens when you click the button, for example 'Upload File', not what the icon looks like, 'Paperclip'. The text is available to users in two ways. - On the tooltip when you hover over the button - As text for assistive technologies Buttons that only show an icon to represent do not have an accessible name. For `lightning-button-icon-stateful`, provide the accessible name using the `aria-label` attribute. Use the following accessibility and `aria` attributes on `lightning-button-icon-stateful`. | Attribute | Type | Description | | ---------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | accesskey | string | A shortcut key to activate or place focus on the button | | aria-atomic | boolean | Specifies whether the screen reader should always present the live region as a whole, even if only part of the region changes. The default is `false`. | | aria-controls | ID reference list | An element ID or a space-separated list of element IDs whose presence or content is controlled by this button. | | aria-describedby | ID reference list | An element ID or a space-separated list of element IDs that provide a descriptive label or description for the button. | | aria-expanded | boolean | Indicates whether the state of an element, controlled by the button, is expanded or collapsed. To reference the controlled element, use `aria-controls`. | | aria-label | string | Provides an assistive label where a visible label cannot be used. | | aria-live | string | Indicates whether the button will be updated, and describes the types of updates assistive technologies will make. Possible values include `off`, `polite`, and `assertive`. The default is `off`. For the screen reader to announce changes when the user is idle, use `polite`. For immediate notifications, use `assertive`. | For more information, see the [WAI-ARIA Specification](https://www.w3.org/TR/wai-aria/). ::::: :::::tab ::component-specification{component="buttonIconStateful" model="lwc" namespace="lightning"} ::::: :::::: # Button Menu **`lightning-button-menu`** Represents a dropdown menu with a list of actions or functions. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="buttonMenu" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-button-menu` component represents a button that shows a dropdown menu of actions or functions when you click it. The menu closes when you click away from it. When you select a menu item, the menu also closes and puts the focus back on the button. Use [`lightning-menu-item`](/docs/platform/lightning-component-reference/guide/lightning-menu-item.html) components nested in `lightning-button-menu` to specify the menu items for the button menu. This example shows how to create a dropdown button menu with three items. To add a text label to the button before the icon, use the `label` attribute. ```html ``` ## Design `lightning-button-menu` implements the menus blueprint in the Salesforce Lightning Design System (SLDS). The menus adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Menus](https://v1.lightningdesignsystem.com/components/menus/) | [Menus](https://www.lightningdesignsystem.com/components/menus/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | The `lightning-button-menu` component supports several variants that change the look of the button. You can use a combination of the `variant`, `icon-name`, and `icon-size` attributes to customize the button and icon styles. For more information, see the [Component Styling](#component-styling) section. ## Checked Menu Items To create menu items that appear with a checkmark, use the `checked` attribute in the `lightning-menu-item` component, toggling it as needed. ```html ``` To enable toggling of a menu item, you must set an initial value on the `checked` attribute, specifying either `true` or `false`. ```javascript import { LightningElement } from "lwc"; export default class ButtonMenuCheckedExample extends LightningElement { isBold = true; // initial value must be true/false isItalic = false; handleSelect(event) { const { value } = event.detail; if (value === "bold") this.isBold = !this.isBold; if (value === "italic") this.isItalic = !this.isItalic; } } ``` ## Create Dividers and Subheadings Use the [`lightning-menu-divider`](/docs/platform/lightning-component-reference/guide/lightning-menu-divider.html) component to create a dividing line after a menu item. Use the [`lightning-menu-subheader`](/docs/platform/lightning-component-reference/guide/lightning-menu-subheader.html) component to create subheadings in the list of menu items. ## Generate Menu Items This example creates a button menu with several items during initialization. When working with an iterator, include a unique `key` value on `lightning-menu-item`. For more information, see [Render Lists](https://developer.salesforce.com/docs/platform/lwc/guide/create-lists.html) in the _Lightning Web Components Developer Guide_. ```html ``` The `items` array definition uses the `@track` decorator to track mutations in the array. If the value of `items` changes, the component's template rerenders. Define `items` and handle the `select` event in your JavaScript code. ```javascript import { LightningElement, track } from "lwc"; export default class DemoButtonMenu extends LightningElement { @track items = [ { label: "Alpha", value: "alpha", }, { label: "Beta", value: "beta", }, { label: "Gamma", value: "gamma", }, ]; handleMenuSelect(event) { // retrieve the selected item's value const selectedItemValue = event.detail.value; // INSERT YOUR CODE HERE } } ``` ## Show the Loading State of a Menu The `is-loading` attribute enables you to show an activity indicator while the menu is loading. You can use this attribute, for example, to inform users that the menu is working while generating a large list of menu items. When `is-loading` is `true`, the menu shows a spinner. Use `loading-state-alternative-text` along with `is-loading` to specify explanatory text such as "Loading menu..." or "Please wait while items load". ```html ``` ## Draft Indicators Use the `is-draft` and `draft-alternative-text` attributes together to indicate that the button menu is in an unsaved state. The draft indicator, an asterisk, is shown for the button menu when `is-draft` is `true`. Use the draft indicator with the `draft-alternative-text` attribute to provide text describing the reason the menu is in a draft state. Use the button menu's draft state to show there’s unsaved state or unsaved data, for example, if a user changes a customizable menu. ```html ``` ## Component Styling Use a combination of the `icon-name`, `icon-size`, `variant`, and `class` attributes to customize the button and icon styles. ### Icons By default, the button shows a utility:down icon to indicate the dropdown function. Use the `icon-name` attribute to place an optional [utility icon](https://v1.lightningdesignsystem.com/icons/#utility) in front of the utility:down icon. Use the `icon-size` attribute to change the icon size from the default size of `medium`. When applying SLDS classes or icons, check that they’re available in the SLDS release tied to your org. The Lightning Design System site shows the latest SLDS resources, which become available only when the new release is available in your org. ### Variants Use the `variant` attribute with one of these values to apply styling. - `border` - The default variant, which shows a gray border around the button's down arrow symbol. The area inside the border is transparent and clickable. - `border-inverse` - Same as the `border` variant except the down arrow is white so it's visible on dark backgrounds. - `border-filled` - Same as the `border` variant, except the area inside the border is white. - `container` - Shows only the down arrow, without a visible border. The clickable area surrounding the down arrow is the same size as the default `border` variant and is transparent. - `bare` - Same as the `container` variant, except the clickable area surrounding the down arrow is smaller than the default. - `bare-inverse` - Same as the `bare` variant except the down arrow is white so it's visible on dark backgrounds. ### Sizes Adjust the button and icon sizes by using the `size` attribute with one of these values. For `bare` and `bare-inverse` variants: - `medium` is the default size, which creates a 14px by 14px icon - `small` creates a 12px by 12px icon - `x-small` creates a 8px by 8px icon - `large` creates a 24px by 24px icon For other variants: - `medium` is the default size, which creates a 32px by 32px button enclosing a 14px by 14px icon. - `small` creates a 24px by 24px button enclosing a 14px by 14px icon - `x-small` creates a 20px by 20px button enclosing a 12px by 12px icon - `xx-small` creates a 16px by 16px button enclosing a 8px by 8px icon ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds padding around the button menu by using an SLDS class. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. `lightning-button-menu` supports these component styling hooks. | CSS Custom Property | `lightning-button-menu` Variants | | ---------------------------------- | ----------------------------------------------------------------------------------------------------------- | | `--slds-c-button-color-background` | `border` (default), `bare`, `bare-inverse`, and `container` | | `--slds-c-button-color-border` | `bare`, `bare-inverse`, and `container` | | `--slds-c-button-text-color` | `border` (default), `bare`, `bare-inverse`,`container`, and `border-filled`; use with the `label` attribute | | `--slds-c-button-text-color-*` | `border` (default), `bare`, `container`, and `border-filled` | | `--slds-c-button-radius-border` | all | | `--slds-c-button-sizing-border` | `bare`, `bare-inverse`, `border-inverse`, and `container` | For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Usage Considerations Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences. This component's menu items are created only if the button is triggered. You can't reference the menu items during initialization or if the button isn't triggered yet. In Lightning Experience, a button menu that's in an open state overlays the record edit page or modal, the global header, and the record form footer when scrolling. You can customize the alignment of the dropdown menu relative to the button by using `menu-alignment`. If you’re using `lightning-button-menu` in a container that specifies the `overflow:hidden` CSS property, setting `menu-alignment="auto"` makes sure that the dropdown menu isn’t hidden from view when the menu is toggled. For mobile devices, set `menu-alignment="auto"` to ensure proper display of the menu. When using this component within `lightning-button-group`, set `variant="border-filled"` on `lightning-button-menu` for a white button background. Otherwise, the `lightning-button-menu` background is transparent by default. ## Accessibility To inform screen readers that a button menu is disabled, set the `disabled` attribute to `true`. Buttons must have an accessible name to enable assistive technology to describe the button's purpose. Provide this name using the `alternative-text` or `label` attribute. Make it a clear action, such as "Show menu". To make the name available to assistive technology but hidden from view, use `alternative-text`. `lightning-button-menu` is rendered with `aria-haspopup="true"` to indicate that the button opens a menu. The component also indicates whether the menu is currently expanded or collapsed using `aria-expanded="true"` or `aria-expanded="false"`. For more information, see the [WAI-ARIA Specification](https://www.w3.org/TR/wai-aria/). To display a contextual popup over the button menu, use the `tooltip` attribute. The popup becomes visible when you hover over the button, or after the button receives keyboard focus. Showing the popup on hover or on keyboard focus ensures that all users can access it, even if they aren’t using a mouse. If you use both `title` and `tooltip` attributes, they are both visible when you hover over the button. Some screen readers don’t support the `title` attribute and many of them don’t read the `title` attribute by default. ```html ``` For sighted users, make sure your descriptions for `title` and `tooltip` are not repetitive. We recommend providing detailed information to `tooltip` and making `title` more concise if you use both. If you use the `is-loading` indicator, use `loading-state-alternative-text` to provide a description for users of assistive devices. If you use the `is-draft` indicator, use `draft-alternative-text` to provide a description for users of assistive devices. ## Custom Events **`select`** The event fired when the menu is selected. The `select` event returns the following parameter. | Parameter | Type | Description | | --------- | ------ | --------------------------------- | | value | string | The value of the selected option. | The event properties are as follows. | Property | Value | Description | | ---------- | ----- | ------------------------------------------------------------------------------ | | bubbles | false | This event does not bubble. | | cancelable | true | This event can be canceled. You can call `preventDefault()` on this event. | | composed | false | This event does not propagate outside the template in which it was dispatched. | **`open`** The event fired when you open the dropdown menu in one of the following ways. - Tab to the button and press the Enter key - Click the button that toggles the dropdown menu The `open` event doesn’t return any parameters. The event properties are as follows. | Property | Value | Description | | ---------- | ----- | --------------------------------------------------------------------------------------------------------- | | bubbles | false | This event does not bubble. | | cancelable | false | This event has no default behavior that can be canceled. You can’t call `preventDefault()` on this event. | | composed | false | This event does not propagate outside of the component in which it was dispatched. | **`close`** The event fired when you close the dropdown menu in one of the following ways. - Select or unselect a dropdown menu item - Click the button that toggles the dropdown menu - Remove focus from the dropdown menu, such as by clicking outside of the dropdown menu or tabbing to another element on the page The `close` event does not return any parameters. The event properties are as follows. | Property | Value | Description | | ---------- | ----- | ---------------------------------------------------------------------------------------------------------- | | bubbles | false | This event does not bubble. | | cancelable | false | This event has no default behavior that can be canceled. You cannot call `preventDefault()` on this event. | | composed | false | This event does not propagate outside of the component in which it was dispatched. | ::::: :::::tab ::component-specification{component="buttonMenu" model="lwc" namespace="lightning"} ::::: :::::: # Button Stateful **`lightning-button-stateful`** A button that toggles between states. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="buttonStateful" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-button-stateful` component represents a button that toggles between states, similar to a Like button on social media. Stateful buttons can show a different label and icon based on their `selected` states. To handle the state change when the button is clicked, use the `onclick` event handler. This example enables you to toggle the button between states, showing the "Follow" label by default, and replacing it with "Following" when the button is selected. Selecting the button toggles the `selected` state to true, and deselecting it toggles `selected` state to false. When the `selected` state is true, the button shows "Unfollow" when you mouse over it or when it receives focus. ```html ``` The `handleClick()` function toggles the state via the `isSelected` attribute. ```javascript import { LightningElement } from "lwc"; export default class MyComponentName extends LightningElement { isSelected = false; handleClick() { this.isSelected = !this.isSelected; } } ``` `lightning-button-stateful` doesn't retrieve the button label from `event.target.label`. To work with the button labels, use the `labelWhenOff`, `labelWhenOn`, and `labelWhenHover` attributes. ## Design `lightning-button-stateful` implements the buttons blueprint in the Salesforce Lightning Design System (SLDS). The buttons adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Buttons (Stateful)](https://v1.lightningdesignsystem.com/components/buttons/#flavor-stateful) | [Buttons (Stateful)](https://www.lightningdesignsystem.com/components/buttons/#flavor-stateful) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Component Styling Use a combination of icon names, variants, and utility classes to style your stateful buttons. ### Icons Use the `icon-name` attribute to add a utility icon to the button. The [SLDS utility icon category](https://v1.lightningdesignsystem.com/icons/#utility) provides nearly 200 utility icons that can be used in `lightning-button-stateful` along with a text label. Although SLDS provides several categories of icons, only the utility category can be used with this component. When applying SLDS classes or icons, check that they are available in the SLDS release tied to your org. The latest SLDS resources become available only when the new release is available in your org. ### Variants Use the `variant` attribute with one of these values to apply styling. - `neutral` is the default variant, a plain uncolored button. - `brand` is a blue button, used to draw attention to the primary action on a page. - `destructive` is a red button used to warn users that its action has a negative effect. - `inverse` uses the background color and light text, useful for dark backgrounds. - `success` is a green button used to indicate a successful action. - `text` is a button without a border, which gives it the look of a plain text link. ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. This example adds padding on the button using an SLDS class. ```html ``` ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. `lightning-button-stateful` contains the same customizable elements as `lightning-button`, which supports `--slds-c-button-*` custom properties. CSS custom properties for stateful buttons work only with particular `lightning-button-stateful` variants. | CSS Custom Property | `lightning-button-stateful` Variants | | ------------------------------- | ------------------------------------ | | `--slds-c-button-*` | all | | `--slds-c-button-color-*` | `base` | | `--slds-c-button-text-color-*` | `neutral` (default) and `text` | | `--slds-c-button-neutral-*` | `neutral` (default) | | `--slds-c-button-brand-*` | `brand` | | `--slds-c-button-destructive-*` | `destructive` | | `--slds-c-button-inverse-*` | `inverse` | | `--slds-c-button-success-*` | `success` | For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Usage Considerations This component has usage differences from its Aura counterpart. See [Base Components: Aura Vs Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/migrate-map-aura-lwc-components) in the Lightning Web Components Developer Guide. ## Accessibility This component uses `aria-live="polite"`, which means the button label is read after the current user task or content. To inform screen readers that a button is disabled, set the `disabled` attribute to true. ::::: :::::tab ::component-specification{component="buttonStateful" model="lwc" namespace="lightning"} ::::: :::::: # Card **`lightning-card`** Cards apply a container around a related grouping of information. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="card" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-card` groups related information in a stylized container. The information can be a single item or a group of items such as a related list. A `lightning-card` can contain a title, body, actions, and a footer. The title, actions, and footer are optional. You can also provide an icon in the header in front of the title. Use the `actions` slot to pass content such as `lightning-button-icon` or `lightning-button` to perform an action when clicked. An action menu is shown on the top corner of the card opposite the title. Here's an example that passes in the title, actions, and footer as slots, and includes an icon. ```html ``` `title` is available as an attribute or a slot. Pass in the title as a slot if you want to pass in markup, such as making the title bold. Use the `title` attribute if your title doesn't need extra formatting. Setting the `title` attribute overwrites the `title` slot. For more information, see [Use Slots as Placeholders](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-slots). ## Design `lightning-card` implements the cards blueprint in the Salesforce Lightning Design System (SLDS). The cards adapt to SLDS 1 or SLDS 2 styling based on the org's theme or the container app that you use. | | SLDS 1 | SLDS 2 | | :------------- | :------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Cards](https://v1.lightningdesignsystem.com/components/cards/) | [Cards](https://www.lightningdesignsystem.com/components/cards/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app, Mobile Offline | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Add an Action to the Footer Slot The card footer is optional and can contain an action to link to another page. If using the card footer, we recommend using a View All link that takes a user to the object list view. This example adds the View All link to the footer slot, specifying the `slds-card__footer-action` class on the <a> tag. This class makes the footer's click target span the entire width of the card so you can click anywhere in the footer. The class isn't required. For a View All link, set the href value of the tag to a URL to take the user to the object list view. ```html ``` To navigate to records, list views, and objects in Lightning Experience, Experience Builder sites, and the Salesforce mobile app, use the navigation service, [`lightning/navigation`](/docs/platform/lightning-component-reference/guide/lightning-navigation.html). For more information, see [Basic Navigation](https://developer.salesforce.com/docs/platform/lwc/guide/use-navigate-basic). ## Card with Illustration A card can present an illustration in the card body when there's no data to show. To maintain a consistent experience, use the [`lightning-illustration` component](/docs/platform/lightning-component-reference/guide/lightning-illustration.html). ```html

Nothing needs your attention right now. Check back later.

``` ## Card with Loading Indicator When you expect content to load with a noticeable delay, a loading indicator is helpful to notify a user of the delay. Use the [`lightning-spinner` component](/docs/platform/lightning-component-reference/guide/lightning-spinner.html) to show a spinner on the card before the content loads. ```html

Loading tasks...

``` ## Card with a Data Table A card is useful for showing a list of related records or contacts. By placing a [`lightning-datatable` component](/docs/platform/lightning-component-reference/guide/lightning-datatable.html) inside the card, you can present tabular information within a card. ```html ``` ## Card with Tiles A card can show records by using tiles. To nest record data in a tile, use the [`lightning-tile` component](/docs/platform/lightning-component-reference/guide/lightning-tile.html). Within a tile, show an icon by using the `media` slot. To make your content responsive, consider using the [`lightning-layout` component] and the SLDS grid system. ```html

Company:

Email:

Salesforce

astro@nomical.com

View All

``` ## Nested Cards A nested card groups data within an object, such as account details with sections for contact info and recent activity. ```html

This is a nested card with no styling (default)

View All

``` ## Component Styling Use a combination of icons and utility classes to customize the card style. ### Icons `lightning-card` displays an SLDS icon if you pass an icon name with the `icon-name` attribute. The icon is rendered using `lightning-icon`. When applying SLDS classes or icons, check that they are available in the SLDS release tied to your org. The latest SLDS resources become available only when the new release is available in your org. Visit [icons](https://v1.lightningdesignsystem.com/icons/) to view available icons. ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute, as shown in the [Add an Action to the Footer Slot](#add-an-action-to-the-footer-slot) section. ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. `lightning-card` also includes [`lightning-icon`](/docs/platform/lightning-component-reference/guide/lightning-icon.html) and [`lightning-button`](/docs/platform/lightning-component-reference/guide/lightning-button.html) components that you can customize by using SLDS styling hooks. ## Usage Considerations Icons aren’t available in Lightning Out, but they’re available in Lightning Components for Visualforce and other experiences. This component has usage differences from its Aura counterpart. See [Base Components: Aura Vs Lightning Web Components](https://developer.salesforce.com/docs/platform/lwc/guide/migrate-map-aura-lwc-components) in the Lightning Web Components Developer Guide. ::::: :::::tab ::component-specification{component="card" model="lwc" namespace="lightning"} ::::: :::::: # Carousel **`lightning-carousel`** A collection of images that are displayed one at a time. **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="carousel" model="lwc" namespace="lightning"} ::::: :::::tab A `lightning-carousel` component shows a series of images in a single container, with image indicators and a control button below the image panel. Only images passed in `lightning-carousel-image` components are supported. Use [`lightning-carousel-image`](/docs/platform/lightning-component-reference/guide/lightning-carousel-image.html) components nested in `lightning-carousel` to specify up to six images. For each image, optionally provide a header and descriptive text that the carousel displays below the image. You can also hyperlink the images. If you specify more than six images, the carousel shows the first six and ignores the rest. The images are shown in the order that you list them in the `lightning-carousel` component. The carousel shows one image at a time, and you can select particular images by clicking the indicators. The carousel can display up to six indicators only. On mobile devices, you can also swipe an image to scroll to the next image. By default, the carousel auto scrolls and loops through the images repeatedly. Each image is visible for 5 seconds before the carousel scrolls to the next image. The control button enables you to pause and restart the automatic scrolling. ## Design `lightning-carousel` 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. | | SLDS 1 | SLDS 2 | | :------------- | :-------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Carousel](https://v1.lightningdesignsystem.com/components/carousel/) | [Cards](https://www.lightningdesignsystem.com/components/carousel/) | | **For Use In** | Lightning Experience, Experience Builder sites, Salesforce mobile app, Lightning Out (Beta), Standalone Lightning app | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Customize Carousel Behavior Disable auto scrolling and remove the control button by including the `disable-auto-scroll` attribute in the `lightning-carousel` tag. The user must then use the indicator buttons to display each image. Disable continuous looping by including the `disable-auto-refresh` attribute. The images scroll one time through and stop at the last image if you include `disable-auto-refresh` but not `disable-auto-scroll`. Change the number of seconds each image is visible for by using the `scroll-duration` attribute. For example, you can create three images for the carousel and disable automatic scrolling. ```html ``` ## Component Styling To implement additional styling for the `lightning-carousel` component, use the Lightning Design System [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment/). ## Accessibility `lightning-carousel` implements the [SLDS carousel blueprint](https://v1.lightningdesignsystem.com/components/carousel/), which follows the [WAI-ARIA Authoring Practices Guide for the carousel pattern](https://www.w3.org/WAI/ARIA/apg/patterns/carousel/). Use the Tab key to move focus to the carousel, then tab again to focus on the indicator buttons. Use right and left arrow keys to scroll to the next or previous image. `lightning-carousel` observes these roles, states, and properties. - The indicator buttons use a `ul` element with `role="tablist"`. - Each indicator button uses an `li` element with `role="presentation"`. - Each list item wraps an anchor tag with `role="tab"`. - Each anchor tag has `aria-selected="false"` when it's not selected. ::::: :::::tab ::component-specification{component="carousel" model="lwc" namespace="lightning"} ::::: :::::: # Carousel Image **`lightning-carousel-image`** 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 ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="carouselImage" model="lwc" namespace="lightning"} ::::: :::::tab Use the `lightning-carousel-image` component to specify images for the [`lightning-carousel`](/docs/platform/lightning-component-reference/guide/lightning-carousel.html) 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. ```html ``` ## Design 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. | | SLDS 1 | SLDS 2 | | :------------- | :-------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------- | | **Design** | [Carousel](https://v1.lightningdesignsystem.com/components/carousel/) | [Carousel](https://www.lightningdesignsystem.com/components/carousel/) | | **For Use In** | Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App | [Lightning Experience](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm&type=5) | ## Use Images in Your Org 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. ```html ``` 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`. ```js import { LightningElement } from "lwc"; import companyLogo from "@salesforce/resourceUrl/company_logo"; import companyProducts from "@salesforce/resourceUrl/company_products"; export default class CarouselStaticResources extends LightningElement { // Expose the static resource URL for use in the template companyLogoUrl = companyLogo; // Expose URL of assets included inside an archive file product1Url = companyProducts + "/product1.png"; product2Url = companyProducts + "/product2.png"; } ``` ## 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. ::::: :::::tab ::component-specification{component="carouselImage" model="lwc" namespace="lightning"} ::::: :::::: # Checkbox **`lightning-input`** _type="checkbox"_ **For Use In** Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline ::::::tabset{tabs='["Example", "Develop", "Specifications"]'} :::::tab ::component-playground{component="checkbox" model="lwc" namespace="lightning"} ::::: :::::tab Checkboxes present one or more options for selection. `lightning-input type="checkbox"` is useful for creating single checkboxes. If you are working with a group of checkboxes, consider using [`lightning-checkbox-group`](/docs/platform/lightning-component-reference/guide/lightning-checkbox-group.html) instead. ```html ``` A checkbox that's disabled is grayed out and you can't interact with it. A disabled checkbox isn't focusable and isn't submitted with the form. Similarly, you can't interact with a read-only checkbox. ## Design `lightning-input` implements designs in the Salesforce Lightning Design System (SLDS). The input types adapt to SLDS 1 or [SLDS 2 styling](https://help.salesforce.com/s/articleView?id=xcloud.customize_ui_enhancedlex.htm) based on the org's theme or the container app that you use. | Input Type | SLDS 1 | SLDS 2 | | ---------- | --------------------------------------------------------------------- | ---------------------------------------------------------------------- | | checkbox | [Checkbox](https://v1.lightningdesignsystem.com/components/checkbox/) | [Checkbox](https://www.lightningdesignsystem.com/components/checkbox/) | ## Read-Only Checkbox Unlike the native `` element, a read-only checkbox that you create using `lightning-input` with `type="checkbox"` and `read-only` attributes isn't focusable. You can't interact with a read-only checkbox and it isn't submitted with the form. A read-only checkbox has these characteristics. - Displays a checkmark icon without an enclosing border when the `checked` attribute is used. - Displays a dotted square icon when the `checked` attribute isn't used. If the checkbox also has `read-only` specified, adding the `required` attribute to a checkbox has no effect. ## Indeterminate Checkbox An indeterminate checkbox shows a dash indicator instead of a checkbox. Use an indeterminate checkbox when you want to show a "Select All" checkbox for a group of checkbox. The indeterminate checkbox shows a dash indicator when only some items in a group are selected. Clicking the checkbox clears the indeterminate state. An indeterminate checkbox with a dash indicator has a `checked` value of `false`. This example shows a "Select All" checkbox and a group of checkboxes. The "select all" checkbox either selects or deselects all the checkboxes in the group. When all the checkboxes are selected and you deselect one of the checkboxes in the group, the "Select All" checkbox becomes an indeterminate checkbox that shows a dash indicator. ```html ``` The checkbox specifies `true` for the `indeterminate` boolean when the selected number of checkboxes is at least 1 but fewer than the total number of checkboxes in the group. In this scenario, only some checkboxes in the group are selected. ```javascript import { LightningElement } from "lwc"; export default class BaseComponents extends LightningElement { checkboxItems = [ { id: "red", label: "Red", checked: false }, { id: "green", label: "Green", checked: true }, { id: "blue", label: "Blue", checked: false }, ]; get selectedCount() { return this.checkboxItems.filter((item) => item.checked).length; } get totalCount() { return this.checkboxItems.length; } get allSelected() { return this.totalCount > 0 && this.selectedCount === this.totalCount; } get someSelected() { return this.selectedCount > 0 && this.selectedCount < this.totalCount; } handleSelectAllChange(event) { const isChecked = event.target.checked; this.checkboxItems = this.checkboxItems.map((item) => ({ ...item, checked: isChecked, })); } handleItemChange(event) { const selectedId = event.target.dataset.id; const isChecked = event.target.checked; this.checkboxItems = this.checkboxItems.map((item) => item.id === selectedId ? { ...item, checked: isChecked } : item, ); } } ``` ## Handle Selections When working with checkboxes and toggle switches, use `this.template.querySelectorAll` to retrieve the array of components. You can use `.filter` to determine which elements are checked or unchecked. The next example displays the values of the selected checkboxes. ```html ``` When you select a checkbox, the `handleCheckboxChange` function updates the `selection` property to display a list of selected checkboxes. ```javascript import { LightningElement } from "lwc"; export default class CheckboxExample extends LightningElement { selection; handleCheckboxChange() { // Query the DOM const checked = Array.from(this.template.querySelectorAll("lightning-input")) // Filter down to checked items .filter((element) => element.checked) // Map checked items to their labels .map((element) => element.label); this.selection = checked.join(", "); } } ``` To programmatically set a checkbox or checkbox button to `checked`, query the element using a custom data attribute. You can't query the internal elements of a Lightning web component. This example uses a custom attribute `data-element` to query the element. The checkbox is selected by clicking a button. ```html ``` Set the element's `checked` property to `true`. ```javascript import { LightningElement } from "lwc"; export default class CheckboxExample extends LightningElement { handleSubscribe(event) { this.template.querySelectorAll('[data-element="subscribe-checkbox"]').forEach((element) => { element.checked = true; }); } } ``` ## Input Validation To ensure the checkbox is selected before form submission, use the `required` attribute. You can programmatically check the checkbox's `checked` property in your validation logic. ```html ``` **note:** For the default error messages, see the [`lightning-input` documentation](/docs/platform/lightning-component-reference/guide/lightning-input.html). To validate the checkbox, check its validity using the `checkValidity()` method or access the `checked` property. If the value isn't valid, the `reportValidity()` method shows the error message below the checkbox. ```javascript import { LightningElement } from "lwc"; export default class CheckboxValidation extends LightningElement { handleSubmit() { const checkbox = this.refs.termsCheckbox; console.log(checkbox.validity.valid); // Returns true or false if (!checkbox.checkValidity()) { checkbox.reportValidity(); return; } // Proceed with form submission } } ``` The `validity` attribute returns an object with read-only boolean properties. For the `checkbox` type, these attributes apply: - `badInput` - Indicates that the value is invalid for any input type - `customError` - Indicates that a custom error has been set using `setCustomValidity()` - `valueMissing` - Indicates that an empty value is provided when the `required` attribute is set for any input type - `valid` - True if none of the preceding properties are true ## Add Field-Level Help To provide contextual help content, specify help text with the `field-level-help` attribute. Field-level help adds an info icon next to the input label, with a tooltip displaying the specified help text. ```html ``` ## Component Styling Use a combination of variants and utility classes to customize your checkboxes. ### Variants Use the `variant` attribute with one of these values to position the labels differently relative to the checkbox. - `standard` is the default, which displays the label above the checkbox. - `label-hidden` hides the label but make it available to assistive technology. If you provide a value for `field-level-help`, the tooltip icon is still displayed. - `label-inline` aligns the label and field horizontally. - `label-stacked` places the label above the field. In most contexts, a stacked label (`standard` or `label-stacked` variant) results in better readability and clarity. Use horizontal labels (`label-inline` variant) when you want to conserve vertical space and have fewer than 10 fields. ### Utility Classes To apply additional styling, use the SLDS [utility classes](https://v1.lightningdesignsystem.com/utilities/alignment) with the `class` attribute. ### Styling Hooks Component styling hooks provide CSS custom properties that use the `--slds-c-*` prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the [SLDS 1 component blueprints](https://v1.lightningdesignsystem.com/components/overview/) for available component styling hooks. For more information, see [Style Components Using Lightning Design System Styling Hooks](https://developer.salesforce.com/docs/platform/lwc/guide/create-components-css-custom-properties) in the Lightning Web Components Developer Guide. ## Accessibility When you use the `label` attribute, the component generates a unique ID for the internal `