Course contentsShow
← React
Lesson 99 of 2,3963. JSX FundamentalsFree lesson

data-* and aria-* Attributes: The kebab-case Exceptions

Why data and ARIA attributes keep their kebab-case naming while most JSX attributes use camelCase.

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:

  1. They're extensible standards (you can create data-anything-you-want)
  2. They need to match their official specifications exactly
  3. 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.