Free Online LWC Playground
Write a Lightning Web Component in HTML, JavaScript and CSS, compile it with the open-source LWC compiler and run it in a preview, all in your browser. Plain LWC only: no Salesforce org, base components or Apex.
Press Run, or Ctrl or Cmd + Enter, to compile and run the component. The three tabs are component.html, component.js and component.css of one component, c-playground. Run again after each edit, and before you download. Salesforce's base components, @salesforce/* imports and wire adapters are not available.
Preview
Console
Output appears here. Press Run, or Ctrl or Cmd + Enter.
How to use
Read the example. It is a shopping list that shows a reactive field, a loop, a conditional, a custom event and a lifecycle hook, with comments in each tab.
Edit component.html, component.js and component.css. Use the tabs above the editor to switch between them.
Press Run, or Ctrl or Cmd + Enter. The compiler (about 0.8 MB compressed) is downloaded the first time it is needed and your browser keeps it, so later runs are quick.
See the component in the Preview, and anything it writes with console.log in the Console. If the code does not compile, the Console and the Preview show the file, line and message.
Press Stop to clear the preview. Edit and Run again to see a change, because the component is compiled again on each run.
Press Run, then the download icon, to save a zip. It has index.html, a page that runs your component by itself, and a source folder with the three files. Open index.html straight from the folder: it needs no network and no server.
Why use this tool
A real LWC compiler
Your files are compiled by Salesforce's open-source LWC compiler, so template errors and class errors are reported the way LWC reports them, with a file and line.
A real LWC engine
The preview runs the open-source LWC engine with its synthetic shadow DOM, so reactivity, lifecycle hooks, events and scoped CSS behave like Lightning Web Components.
Three files, one component
component.html, component.js and component.css make the component c-playground, the same split you use in a real project.
Errors with a place
Compile errors name the file and line. Unsupported imports, decorators and tags get a plain explanation instead of a failure that is hard to read.
Sandboxed and offline
The preview runs in an isolated frame with no network access, and the compiler runs in a background worker with a 20 second limit.
Download that runs
The zip has a page that runs your component from a file, with the LWC engine inside it, and your three source files.
About this tool
Write a Lightning Web Component and see it run, without a Salesforce org. The editor has three tabs, component.html, component.js and component.css, which make one component called c-playground. When you press Run, the component is compiled in your browser by the open-source LWC compiler and drawn by the open-source LWC engine inside a sandboxed preview. This is plain Lightning Web Components: reactive fields and @track, @api properties, getters, lifecycle hooks, lwc:if and for:each, event handlers, custom events, slots and scoped CSS all work. Everything that comes from a Salesforce org does not: Salesforce's own base components (lightning-button, lightning-card, lightning-input and the rest), imports from @salesforce/* and lightning/*, wire adapters, Lightning Data Service and Apex calls are not included, and the tool says so when your code uses them. The compiler and engine are Salesforce's open-source LWC packages, version 9.6.0, hosted on this site. Your code is compiled and run in your browser. This tool is not affiliated with or endorsed by Salesforce.
Frequently asked questions
No. It uses Salesforce's open-source LWC compiler and engine, which is the same framework Lightning Web Components are built on. It is not a Salesforce org and has none of its services, and this tool is not affiliated with or endorsed by Salesforce. A component that works here can still behave differently in an org, which has its own base components, security rules and API versions.
They are Salesforce's own base components. They are part of the platform and are not part of the open-source LWC packages, so they are not included here. The playground reports each one with its line. Use plain HTML elements instead, such as button, input and div, and style them in component.css.
Only lwc, for example import { LightningElement, api, track } from 'lwc'. Imports from @salesforce/* (apex, schema, label, user, resourceUrl), from lightning/* (navigation, platformShowToastEvent and the others), from other components (c/something) and from the internet are refused with a message that names the line.
No. Wire adapters and Lightning Data Service come from a Salesforce org, so a component that uses @wire is reported with its line. Keep data in plain fields and methods.
Not in this version. There is one component, c-playground. A tag such as c-child is reported as an error. Slots work inside the one component, but with no parent there is nothing to fill them.
lwc:if, lwc:elseif and lwc:else, if:true and if:false, for:each and iterator, key, lwc:ref, expressions such as {name} and {item.id}, event handlers such as onclick and onchange, and dynamic class and style from getters. Complex JavaScript expressions in the template are not allowed, as in LWC itself: use a getter.
No. The LWC Playground has no data of its own and cannot call Apex. It runs only the JavaScript you write.
In your browser. The compiler runs in a background worker, and the preview has no network access. The compiler and engine are files on this site, loaded when the playground first runs, and nothing else is requested.
Compiling is stopped after 20 seconds. The preview itself is not time limited, so a loop that never ends in your component can freeze the preview. Press Stop, fix the loop and run again.
Compile errors point at your own files. An error thrown while the component runs is reported with the line of the compiled script, not your file, so read the message and the stack rather than the number.
Your latest code is kept in this browser on this device so it is still there when you come back. It is not run again until you press Run. The built-in example runs on your first visit.
Version 9.6.0 of Salesforce's open-source LWC packages. The Console shows the version on every successful run. The platform's own release may differ.