Lesson 6 of 3020%

(Progress persistence is disabled until Phase 9)

React
Beginner

JSX Attributes

How to pass attributes to HTML elements in JSX.

HTML attributes work mostly the same in JSX, but with a few important differences because JSX is closer to JavaScript than HTML.

camelCase Naming

Attributes in JSX use camelCase.

  • onclick becomes onClick
  • tabindex becomes tabIndex

The class Attribute

Because class is a reserved keyword in JavaScript, React uses className instead.

function App() {
  const imageSrc = "https://example.com/logo.png";

  return (
    <div className="container">
      <img src={imageSrc} alt="Company Logo" />
    </div>
  );
}

Notice how we can use curly braces to pass a JavaScript variable directly to the src attribute!

Try It Yourself

Lesson Progress

Take QuizBuild a React Project