Develop Secure Code
Understand Lightning Out 2.0 Architecture
Set Component Styles and Properties in a Lightning Out 2.0 App
Handle Lightning Out 2.0 App Events
Lightning Out 2.0 Limitations
Learn how Lightning Out 2.0 provides access to Salesforce on external host pages while securely encapsulating embedded Lightning web components (LWCs). Examine the Lightning Out 2.0 app code and understand how the elements interact with each other and the host page.
Include the Lightning Out 2.0 JavaScript library as a script on the external host page.
1<script
2 type="text/javascript"
3 async=""
4 src="https://MY_DOMAIN_NAME.my.salesforce.com/lightning/lightning.out.latest/index.iife.prod.js"
5></script>The Lightning Out 2.0 code block that the Lightning Out 2.0 App Manager provides includes the script element and its attributes. See Build a Lightning Out 2.0 App in Salesforce Help.
When a host page initializes the Lightning Out 2.0 script, custom web components are created in the context of the external host page. One of these components is lightning-out-application, which contains the base configuration for the Lightning Out 2.0 app. It doesn’t have a UI element.
1<lightning-out-application
2 frontdoor-url="https://MY_DOMAIN_NAME.salesforce.com/secur/frontdoor.jsp?..."
3 app-id="18_DIGIT_SALESFORCE_ID"
4 components="c-my-lwc,complex_ns-lwc-component"
5>
6</lightning-out-application>lightning-out-application requires three attributes.
frontdoor-urlThe frontdoor URL used to establish the Salesforce session. You must set this attribute dynamically at run time. See Set Up Authentication for Lightning Out 2.0 in Salesforce Help.
app-idThe 18-digit Lightning Out 2.0 app ID, for example 1Usfi200000006TCAQ. You can find this value in the Lightning Out 2.0 App Manager in Setup. If you created a Lightning Out 2.0 app before Spring ’26, this attribute isn’t required.
componentsA comma-separated list of LWC components to embed in the external page. Use the format c-my-component, where hyphens (-) separate the namespace and the parts of the component name. If the namespace is mixed cased, separate the parts of the namespace with an underscore (_). For example, enter complex_ns-lwc-component for complexNs/lwcComponent. You must also add the components to the Lightning Out 2.0 app in the Lightning Out 2.0 App Manager. See Build a Lightning Out 2.0 App in Salesforce Help.
The Lightning Out 2.0 code block that the Lightning Out 2.0 App Manager provides includes lightning-out-application, as well as the app-id and components attributes.
The other Lightning Out 2.0 web components mirror the LWC components added to the Lightning Out 2.0 app. The names of these components are defined in the components attribute of lightning-out-application.
1<c-my-lwc style="--custom-color: brown;"></c-my-lwc>
2<complex_ns-lwc-component
3 ex-attr="ex-value"
4 other-ex-attr="other-ex-value"
5></complex_ns-lwc-component>Each Lightning Out 2.0 web component contains an iframe that becomes the root of a closed shadow DOM. Because the iframe is in the shadow DOM, JavaScript on the host page can’t directly see or manipulate content inside the iframe. Inside the iframe, the actual LWC component runs in the Salesforce context instead of the context of the host page.
On each Lightning Out 2.0 web component, you can set values for any attribute that the corresponding LWC component supports. Passing an unsupported attribute doesn’t trigger compilation or run-time errors, but that attribute’s value isn’t set on the LWC component. You can set supported attributes declaratively with HTML, programmatically with JavaScript, or as JSON properties in the Lightning Out 2.0 App Manager.
For example, the Lightning Out 2.0 component c-my-lwc has a style attribute set to "--custom-color: brown;". style is a global attribute, and the LWC component c-my-lwc has the CSS custom property --custom-color defined in its stylesheet. Therefore, the Lightning Out 2.0 component c-my-lwc can pass this attribute to the LWC component c-my-lwc in the iframe and override its styling. To learn more about passing attributes, see Set Component Styles and Properties in a Lightning Out 2.0 App.
To show how the elements of a Lightning Out 2.0 app work together, here’s the expanded markup for a Lightning Out 2.0 app as it’s embedded in a host page.
1<!-- Host page context-->
2<body>
3 <!--Lightning Out 2.0 JS library -->
4 <script
5 type="text/javascript"
6 async=""
7 src="https://MY_DOMAIN_NAME.my.salesforce.com/lightning/lightning.out.latest/index.iife.prod.js"
8 ></script>
9 <!-- Lightning Out 2.0 web component: base configuration -->
10 <lightning-out-application
11 app-id="18_DIGIT_SALESFORCE_ID"
12 frontdoor-url="https://MY_DOMAIN_NAME.salesforce.com/secur/frontdoor.jsp?..."
13 components="c-my-lwc"
14 >
15 </lightning-out-application>
16 <!-- Lightning Out 2.0 web component -->
17 <c-my-lwc style="--custom-color: brown;">
18 <!-- shadow DOM open -->
19 <iframe>
20 <html>
21 <!-- Salesforce context -->
22 <body>
23 <!-- Lightning web component -->
24 <c-my-lwc style="--custom-color: brown;"></c-my-lwc>
25 </body>
26 </html>
27 </iframe>
28 <!-- shadow DOM close -->
29 </c-my-lwc>
30</body>To track the lifecycle of a Lightning Out 2.0 app, Lightning Out 2.0 fires these custom events.
lo.application.ready: Fires if a Salesforce session is successfully established.lo.application.error: Fires if a Salesforce session can’t be established. The detail property of the event has two properties.
message: The error message.originalError: The original error generated inside the Salesforce context.lo.component.ready: Fires if a Lightning Out 2.0 component successfully renders with the embedded LWC component.lo.component.error: Fires if a Lightning Out 2.0 component either fails to render or encounters an error from the embedded LWC component during run time. The detail property of this event has two properties.
message: The error message.originalError: The original error generated inside the Salesforce context.With these events in mind, let’s summarize the Lightning Out 2.0 app initialization flow.
frontdoor-url attribute on lightning-out-application.lightning-out-application app and establish a Lightning Out 2.0 session.lo.application.ready custom event.lo.component.ready custom event.See Also