JSX

JSX is a syntax extension for JavaScript that lets you write HTML-like markup directly inside your code. React uses JSX to describe what the UI should look like.

React

JSX is not a string and not HTML — it is syntactic sugar that a build tool compiles into regular JavaScript function calls. A tag like <h1>Hi</h1> becomes a call that creates a React element describing that heading.

Inside JSX you can embed any JavaScript expression by wrapping it in curly braces { }. Because JSX compiles to JavaScript, attributes use camelCase (className instead of class, onClick instead of onclick), and every set of tags must have exactly one parent element.

Examples

JSX — The {name} expression is evaluated, so the paragraph renders as 'Hello, Sam!' with a CSS class of 'greeting'.

const name = "Sam";
const element = <p className="greeting">Hello, {name}!</p>;

Learn it in a lesson

See also

Back to the Dictionary