data-* and aria-* Attributes: The kebab-case Exceptions
What you'll learn: Why data-* and aria-* attributes are the only JSX attributes that keep their kebab-case naming instead of converting to camelCase.
The Unexpected Exception
You've learned that JSX converts HTML attributes to camelCase: class becomes className, for becomes htmlFor, onclick becomes onClick. But there are two special families of attributes that keep their original kebab-case naming: data-* and aria-*.
// These stay in kebab-case:
<button
data-test-id="submit-btn"
data-user-role="admin"
aria-label="Close dialog"
aria-hidden="true"
>
Submit
</button>
// NOT this (wrong):
<button
dataTestId="submit-btn"
ariaLabel="Close dialog"
>
Submit
</button>
Why the Exception?
Data attributes (data-*) are a web standard for storing custom information on HTML elements. They're explicitly designed to allow any name after the data- prefix.
ARIA attributes (aria-*) provide accessibility information to screen readers. They follow the official W3C specification, which uses kebab-case naming.
React preserves the exact spelling for both families because:
- They're extensible standards (you can create
data-anything-you-want) - They need to match their official specifications exactly
- External tools and libraries expect these exact attribute names in the DOM
Key Takeaway: data-* and aria-* attributes are the only kebab-case attributes in JSX—all others use camelCase. This exception exists to maintain compatibility with web standards and accessibility specifications.