Lightning Web Components are built with a consistent folder structure and a small set of core files. This post explains the role of each file and how they work together.
Every component lives in its own folder and contains at least these files:
myComponent/
myComponent.html
myComponent.js
myComponent.js-meta.xml
myComponent.css
The HTML file defines the component UI and binds data from JavaScript. Use standard HTML plus LWC directives.
<template>
<lightning-card title="Account Info" icon-name="standard:account">
<div class="slds-m-around_medium">
<p>Name: {accountName}</p>
<lightning-button
label="Refresh"
onclick={handleRefresh}
variant="brand"
></lightning-button>
</div>
</lightning-card>
</template>
{property} for one-way bindingif:true / if:false for conditional renderingfor:each for list iterationonclick, onchange, and other event handlersThe JavaScript file defines component state, methods, and decorators that control reactivity.
import { LightningElement, api, track } from 'lwc';
export default class MyComponent extends LightningElement {
@api recordId; // Public property from parent
@track isLoading = false; // Reactive property
accountName = 'Acme Corp'; // Private property
handleRefresh() {
this.isLoading = true;
setTimeout(() => {
this.isLoading = false;
}, 500);
}
}
@api – expose public properties and methods@track – track nested property changes (less needed with simple fields)@wire – connect to data services or Apex
The .js-meta.xml file configures component visibility, targets, and API version.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>57.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordPage">
<objects>
<object>Account</object>
</objects>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
isExposed – make it available in App BuilderOptionally add these files for richer functionality:
The framework compiles and bundles these files. The JS file handles state and behavior, the HTML file renders markup, and the meta file controls deployment and visibility.
@api for public data and methods{property} binding to display JS values