Which token is used for applying CSS classes in JSX?

Master ReactJS with our comprehensive test. Practice with multiple-choice questions and detailed explanations. Build your skills for the exam with our engaging format and expert tips!

Multiple Choice

Which token is used for applying CSS classes in JSX?

Explanation:
In JSX, applying CSS classes is done with className instead of class. This matches the JavaScript DOM property name, since class is a reserved keyword in JavaScript. React translates the className attribute to the element’s actual class attribute when rendering, so your styles apply correctly. The other options aren’t standard in React: class would clash with JavaScript syntax, styleName is not a general React attribute (it’s used only by certain libraries), and cssClass isn’t recognized by React as a way to set classes. So using className, as in <div className="btn primary">, is the correct approach.

In JSX, applying CSS classes is done with className instead of class. This matches the JavaScript DOM property name, since class is a reserved keyword in JavaScript. React translates the className attribute to the element’s actual class attribute when rendering, so your styles apply correctly. The other options aren’t standard in React: class would clash with JavaScript syntax, styleName is not a general React attribute (it’s used only by certain libraries), and cssClass isn’t recognized by React as a way to set classes. So using className, as in

, is the correct approach.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy