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

className vs class: The JSX Naming Convention

Why JSX uses className instead of class, and how this reflects JSX's JavaScript nature rather than HTML.

className vs class: The JSX Naming Convention

What you'll learn: Why JSX uses className instead of class to apply CSS classes, and what this reveals about JSX's true nature.

The HTML Instinct

When you first write JSX, you might naturally reach for the HTML class attribute to style elements:

// This feels right, but it's WRONG in JSX:
<div class="header">Welcome</div>

React will warn you about this. Instead, you must write:

// CORRECT in JSX:
<div className="header">Welcome</div>

Why the Difference?

Remember: JSX compiles to JavaScript, not HTML. Under the hood, your JSX becomes React.createElement() calls that create JavaScript objects.

In JavaScript, class is a reserved keyword (used for defining classes). If JSX allowed class, it would conflict with JavaScript's own syntax and confuse the compiler.

Since className is the actual DOM property name in JavaScript (check document.createElement('div').className), JSX aligns with JavaScript conventions rather than HTML.

The Pattern

This isn't unique to class. JSX follows JavaScript naming for DOM properties:

  • HTML's for (reserved in JS) → JSX's htmlFor
  • HTML's tabindex → JSX's tabIndex (camelCase)

An Analogy

Think of HTML as the tourist-friendly menu, while JSX speaks the kitchen's language. You're not writing HTML markup—you're writing JavaScript instructions that describe what HTML should eventually appear.

Key Takeaway: JSX uses className because JSX is JavaScript first, not HTML. The class keyword is reserved in JavaScript, so React uses the DOM property name className instead.