Sub topic 3
Naming: camelCase in JavaScript, kebab-case in markup
This chapter assumes you can build a simple Lightning web component and use {property} expressions in a template. It also assumes you know how to mark a field with @api so a parent can set it. Here you learn how a property name in the child's JavaScript maps to an attribute name in the parent's HTML.
Two naming styles for one name
JavaScript class fields use camelCase, such as dueDate. HTML attributes are case-insensitive, so the parent writes the same name in kebab-case, with lowercase words joined by hyphens, such as due-date.
The framework converts between the two. You write the property once in the child and use the hyphenated form wherever you set it from markup.
// taskCard.js (child)
import { LightningElement, api } from 'lwc';
export default class TaskCard extends LightningElement {
@api heading;
@api dueDate;
@api assignedToUser;
}<!-- taskBoard.html (parent) -->
<template>
<c-task-card
heading="Write documentation"
due-date="2026-12-15"
assigned-to-user="Priya">
</c-task-card>
</template>Inside the child, you still read the values as this.dueDate and {dueDate}. The kebab-case name appears only in the parent's markup.
The same rule applies to the component tag
The component's folder name follows the same pattern. A component in a folder named taskCard in the default c namespace is written <c-task-card>. The namespace comes first, then a hyphen, then the kebab-case name.
| JavaScript or folder name | Markup name |
|---|---|
| `heading` | `heading` |
| `dueDate` | `due-date` |
| `assignedToUser` | `assigned-to-user` |
| `taskCard` (component) | `c-task-card` |
A name with a single word has no hyphen, so heading is identical in both places.
Rules for choosing property names
Some names cause trouble, so pick them with care.
- Start the name with a lowercase letter. Names beginning with an uppercase letter do not map to a usable attribute.
- Do not begin a name with
data, as indataSource. The attributedata-sourceis treated as a custom data attribute and is not passed to your property. - Do not begin a name with
aria, as inariaLabelText, because it collides with built-in accessibility attributes. - Do not use names that match global HTML attributes, such as
title,hidden,idorclass, unless you intend to use that behavior. For example, a publictitleproperty overlaps with the standardtitleattribute. - Do not use a reserved word such as
fororclassas a property name.
// Avoid
@api dataSource;
@api ariaLabelText;
// Prefer
@api source;
@api labelText;Use the hyphenated form in markup only
A common mistake is writing the camelCase name in the parent's template. HTML lowercases attribute names, so dueDate="..." becomes duedate, which matches no property. The child's field stays undefined, and the framework gives no error.
<!-- Wrong: sets nothing -->
<c-task-card dueDate="2026-12-15"></c-task-card>
<!-- Right -->
<c-task-card due-date="2026-12-15"></c-task-card>When you query the component from JavaScript, use the property name, not the attribute name. Setting a property on the element uses camelCase.
// app.js (parent)
renderedCallback() {
const card = this.template.querySelector('c-task-card');
card.dueDate = '2026-12-15';
}This works, but binding in the template is usually clearer. You will see that in the next chapter.
Exercise
A child component declares @api maxItemCount;. How does the parent set it to 10 in its template, and what happens if the parent writes maxItemCount="10" instead?
Show answer
The parent writes max-item-count="10". With maxItemCount="10", HTML lowercases the attribute to maxitemcount, which matches no public property, so maxItemCount stays undefined in the child.
Exercise
Why should you avoid naming a public property dataSource?
Show answer
The attribute form data-source begins with data-, which HTML treats as a custom data attribute. It is not passed to the property, so the value never reaches the child. Rename it to something like source.