Skip to main content
⚑ OpenDevDocs
React
frontendreactGuideBeginner

JSX (JavaScript XML) Syntax Guide

Mastering JSX: syntax rules, embedding JavaScript expressions with curly braces {}, Fragments, className, and style objects.

Verified: 2026-09-30
Tested on:react 19.x
Platforms:
web
#react#jsx#syntax#fragments

JSX (JavaScript XML) Syntax Guide

JSX is a syntax extension for JavaScript that lets you write HTML-like markup directly inside a JavaScript/TypeScript file.


1. Core JSX Syntax Rules

  1. Return a Single Root Element (Use Fragments <>...</>):
    return (
      <>
        <h1>OpenDevDocs</h1>
        <p>Learn. Build. Debug. Deploy.</p>
      </>
    );
  2. Close All Tags Explicitly: Self-closing tags must end with /> (e.g. <img src="..." alt="" />, <input />, <br />).
  3. CamelCase Property Names:
    • class becomes className
    • for becomes htmlFor
    • tabindex becomes tabIndex
    • onclick becomes onClick

2. Embedding JavaScript Expressions with {}

Any valid JavaScript expression (variables, function calls, arithmetic, ternary conditions) can be embedded inside JSX using curly braces {}:

export function Greeting({ username }: { username: string }) {
  const isMorning = new Date().getHours() < 12;

  return (
    <div className="banner">
      <h2>Good {isMorning ? "Morning" : "Evening"}, {username.toUpperCase()}!</h2>
      <p>Active issues: {10 + 4}</p>
    </div>
  );
}

On this page