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

camelCase Attributes: style, onClick, onChange

How JSX attributes use camelCase (onClick, onChange) instead of HTML's lowercase or kebab-case conventions.

camelCase Attributes: style, onClick, onChange

You'll learn: Why JSX uses camelCase for attributes like onClick and onChange instead of HTML's lowercase conventions.

The Naming Convention Shift

In HTML, event attributes are lowercase: onclick, onchange, onkeydown. CSS properties use kebab-case: background-color, font-size. But JSX follows JavaScript naming conventions instead.

Why the difference? JSX is JavaScript, not HTML. When you write onClick, you're actually setting a JavaScript property on a DOM element object. JavaScript property names traditionally use camelCase, so JSX does too.

Common camelCase Attributes

Here are the most frequent examples:

Events:

  • HTML: onclick → JSX: onClick
  • HTML: onchange → JSX: onChange
  • HTML: onkeydown → JSX: onKeyDown
  • HTML: onmouseover → JSX: onMouseOver

The style Attribute:

// HTML uses kebab-case strings:
// <div style="background-color: blue; font-size: 16px;">

// JSX uses camelCase object properties:
<div style={{ backgroundColor: 'blue', fontSize: 16 }}>

Note that style takes a JavaScript object with camelCase property names, not a string.

The Pattern

Think of it this way: if the HTML attribute has multiple words, JSX capitalizes each word after the first. The attribute becomes a valid JavaScript identifier that matches DOM API property names.

This consistency makes sense because React is ultimately calling JavaScript methods like element.addEventListener('click', ...) behind the scenes.

Key Takeaway: JSX attributes follow JavaScript camelCase conventions (onClick, onChange) instead of HTML lowercase because JSX compiles to JavaScript objects, and you're setting properties, not HTML attributes.