Salesforce Consulting

Introduction to Lightning Web Components (LWC) in Salesforce – With Real Code Examples

If you already know HTML, CSS, and JavaScript, LWC will feel very natural to you. That’s exactly why Salesforce introduced it — to bring web standards into the Salesforce ecosystem.

Shailendra Singh Parmar
Founder
March 30, 2026
5 min

In this blog, we’ll understand:

  • What LWC is
  • Why Salesforce uses it
  • LWC folder structure
  • A real working component with code
  • Best practices used by professionals
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JS Button Example</title>
</head>
<body>

  <script src="script.js"></script>
</body>
</html>

What is Lightning Web Components?

Lightning Web Components (LWC) is a UI framework built by Salesforce using modern web standards like:

  • Custom Elements
  • Shadow DOM
  • ES6 JavaScript
  • HTML templates

Earlier, Salesforce used Aura Components, which were powerful but heavy and complex.
LWC is lighter, faster, and much easier to maintain.

Why Salesforce Introduced LWC

Salesforce introduced LWC to solve real problems faced by developers and users.

Key reasons:

  • Faster page loading
  • Better performance on large data
  • Cleaner code structure
  • Easy integration with backend (Apex)
  • Reusable UI components
  • Better user experience

For enterprise applications like Salesforce, performance and scalability matter a lot, and LWC delivers both.

helloWorld
│── helloWorld.html
│── helloWorld.js
│── helloWorld.js-meta.xml
Lightning Web Components bring the power of modern web standards into Salesforce, making enterprise apps faster, cleaner, and truly scalable.

Step 1: HTML File (UI Layout)

This file defines what the user sees.

<template>
    <lightning-card title="Hello LWC">
        <div class="slds-p-around_medium">
            <p>Hello, {name}!</p>

            <lightning-input 
                label="Enter your name"
                value={name}
                onchange={handleChange}>
            </lightning-input>

            <lightning-button 
                label="Submit"
                variant="brand"
                onclick={handleClick}>
            </lightning-button>
        </div>
    </lightning-card>
</template>

Step 2: JavaScript File (Logic)

This file controls how the component behaves.

import { LightningElement, track } from 'lwc';

export default class HelloWorld extends LightningElement {
    @track name = 'User';

    handleChange(event) {
        this.name = event.target.value;
    }

    handleClick() {
        console.log('Button clicked');
    }
}

Best Practices Used by Salesforce Professionals

  • Keep components small and reusable
  • Never put business logic in UI
  • Use Apex only when required
  • Handle errors gracefully
  • Follow SLDS (Salesforce Lightning Design System)
  • Optimize performance using @wire and caching

Final Thoughts

Lightning Web Components are the future of Salesforce UI development.
They combine the best of modern web development with Salesforce’s powerful platform.

Salesforce Implementation That Actually Moves the Needle

Most Salesforce implementations go live. Ours go to work. We configure, integrate, and deploy Salesforce so your teams operate faster, your data works harder, and your business grows without the friction.