Sub topic 3
Naming: camelCase in JavaScript, kebab-case in markup
This chapter covers how a public property name in a child's JavaScript class maps to an attribute name in a parent's HTML template. It also covers the same mapping for component tags, and the reserved names you should avoid.
It assumes you can create a basic Lightning web component and use {expression} bindings in a template. It also assumes you know what @api does from the previous chapter. Examples use a small taskCard component.
Why two naming styles exist
JavaScript identifiers are case-sensitive and cannot contain hyphens. HTML attribute names are case-insensitive. The browser's HTML parser lowercases attribute names, so dueDate and duedate are the same attribute in markup.
Lightning Web Components resolves this with a fixed convention:
- In JavaScript, you write public properties in camelCase, such as
dueDate. - In a parent's HTML template, you write the matching attribute in kebab-case, such as
due-date.
The framework converts between the two. You never write the conversion yourself.
The mapping rule
Each uppercase letter in the camelCase name becomes a hyphen followed by the lowercase letter. A name with no uppercase letters is unchanged.
| JavaScript property | Attribute in parent markup |
|---|---|
| `heading` | `heading` |
| `dueDate` | `due-date` |
| `assignedToUser` | `assigned-to-user` |
| `isUrgent` | `is-urgent` |
| `maxItemCount` | `max-item-count` |
Here is a child that exposes a multi-word property.
// taskCard.js (child)
import { LightningElement, api } from 'lwc';
export default class TaskCard extends LightningElement {
@api heading;
@api dueDate;
}<!-- taskCard.html (child) -->
<template>
<article>
<h3>{heading}</h3>
<p>Due: {dueDate}</p>
</article>
</template>The parent sets dueDate with the attribute due-date.
<!-- taskBoard.html (parent) -->
<template>
<c-task-card heading="Write documentation" due-date="2026-12-15"></c-task-card>
</template>Inside the child, the value is still read as this.dueDate and {dueDate}. The kebab-case form exists only in the parent's markup.
Mapping works in both directions
The rule applies to every place a parent names a child's property in markup. That includes static values and bindings to the parent's own fields.
<!-- taskBoard.html (parent) -->
<template>
<c-task-card heading="Review pull request" due-date={reviewDeadline}></c-task-card>
</template>// taskBoard.js (parent)
import { LightningElement } from 'lwc';
export default class TaskBoard extends LightningElement {
reviewDeadline = '2026-12-01';
}The name on the left of the equals sign is the child's property in kebab-case. The name inside the braces is the parent's own field, written exactly as it appears in the parent's class. The braces contain a JavaScript reference, so that name stays camelCase.
A common source of confusion is mixing the two. In due-date={reviewDeadline}, the left side follows the attribute convention. The right side follows the JavaScript convention.
Component tag names
Component names follow a similar convention. The folder and file names use camelCase. The tag in markup uses the namespace, a hyphen, and the kebab-case component name.
| Namespace | Folder name | Tag in markup |
|---|---|---|
| `c` | `taskCard` | `c-task-card` |
| `c` | `searchBox` | `c-search-box` |
| `c` | `taskList` | `c-task-list` |
The c namespace is the default for components in your own org or project. If a component lives in another namespace, such as a managed package, that namespace replaces c in the tag.
Note that you write a closing tag every time. Custom elements cannot be self-closing, so <c-task-card /> does not work as you might expect. Use <c-task-card></c-task-card>.
Names to avoid for public properties
Not every valid JavaScript name is a good public property name. These cases cause the most trouble.
Names that start with `data`
An attribute that starts with data- is treated as a custom data attribute in HTML. A public property whose name begins with data can collide with this meaning. For example, dataSource maps to data-source, which the platform treats as a data attribute, not as your property. Choose a different name, such as source or recordSource.
Names that start with `on`
Attributes that start with on are treated as event handler attributes. A property such as onClose conflicts with this convention. In LWC, a template attribute like onclose={handleClose} attaches a listener for an event named close. If you named a property onClose, the parent would not be able to set it as you intend. Use a name such as closeLabel or isClosable.
Names that start with `aria`
Names that begin with aria can collide with the platform's accessibility properties. Prefer names that describe your own data, for example labelText.
Names that match global HTML attributes
Global HTML attributes such as title, hidden, id, class, style, slot, lang and tabindex already have meaning on every element. A public property with one of these names can behave differently from what you expect. Some of them are valid, and the base Lightning components use title deliberately, but treat them as a choice you make with care. In a new component, a more specific name such as heading or cardTitle avoids ambiguity.
Names that are reserved by the framework
Do not name a public property slot or part. These are reserved by the platform. Also avoid names that clash with the properties of LightningElement and HTMLElement, such as template, children and dispatchEvent.
What happens when the name is wrong
LWC does not always report a naming mistake. The result depends on what you wrote.
- A camelCase attribute in the parent. If the parent writes
dueDate="...", the HTML parser lowercases it toduedate. The child has no property namedduedate, so the value is not delivered. Nothing is set ondueDate, and the child shows its default value. - A typo in the kebab-case name. If the parent writes
due-day="...", no public property matches. The value is ignored silently. - A kebab-case name on a field that is not public. If the child declares
dueDatewithout@api, settingdue-datefrom the parent has no effect. The field is private to the child.
In all three cases the child renders without an error, but with an empty or default value. When a value does not arrive, check the name first.
A worked debugging example
Suppose a parent sets a value and the child shows nothing.
<!-- taskBoard.html (parent), with a bug -->
<template>
<c-task-card heading="Plan release" dueDate="2026-12-20"></c-task-card>
</template><!-- taskCard.html (child) -->
<template>
<article>
<h3>{heading}</h3>
<p>Due: {dueDate}</p>
</article>
</template>The heading appears, and the due date line shows only "Due:". The parent used dueDate instead of due-date. To debug:
- Confirm the child declares
@api dueDate. If the decorator is missing, the property is not public. - Compare the parent's attribute with the mapping rule. Replace each capital letter with a hyphen and a lowercase letter.
- Correct the markup to
due-date="2026-12-20". - Reload and confirm that the child shows the date.
The fixed version looks like this.
<!-- taskBoard.html (parent), fixed -->
<template>
<c-task-card heading="Plan release" due-date="2026-12-20"></c-task-card>
</template>Setting properties from JavaScript
The kebab-case rule applies only to markup. If the parent finds the child element in JavaScript and sets a property directly, it uses the camelCase property name, as in any JavaScript object.
// taskBoard.js (parent)
import { LightningElement } from 'lwc';
export default class TaskBoard extends LightningElement {
handleSetDeadline() {
const card = this.template.querySelector('c-task-card');
// Use the camelCase name here, not 'due-date'.
card.dueDate = '2026-12-31';
}
}querySelector takes a CSS selector, so it uses the kebab-case tag name c-task-card. The property you set on the result uses camelCase. Treat this as a special case. In most components, you should pass values through template bindings and keep direct assignment for rare needs.
A quick reference
Use this checklist when you wire a parent to a child.
- Declare the property in the child with
@apiand a camelCase name. - Write the attribute in the parent's markup in kebab-case.
- Use camelCase for the parent's own fields inside
{ }. - Use the kebab-case tag name, with a closing tag.
- Avoid names that start with
data,onoraria, and avoid reserved names.
Exercise
A child component declares @api maxItemCount;. A parent writes <c-task-list maxItemCount="5"></c-task-list>, and the child shows no limit. What is wrong, and what is the corrected markup?
Show answer
The HTML parser lowercases the attribute to maxitemcount, which does not match the property maxItemCount, so the value is never delivered. The attribute must be kebab-case: <c-task-list max-item-count="5"></c-task-list>.
Exercise
Give the tag name and the attribute name a parent uses to set the public property assignedToUser on a component whose folder is taskOwnerBadge in the c namespace. Then explain why @api dataSource is a poor property name.
Show answer
The tag is c-task-owner-badge and the attribute is assigned-to-user, for example <c-task-owner-badge assigned-to-user="Ana"></c-task-owner-badge>. The name dataSource maps to data-source, which starts with data- and is treated by HTML as a custom data attribute, so it can collide with your property. A name such as source is safer.