OnlineCBT Logo OnlineCBT
React Tutorial
REACT · LESSON 2

JSX Syntax and Rendering Elements

By Ratan Updated: 16 Oct 2026

Master JavaScript XML (JSX) syntax, embedding expressions, and rendering elements with ReactDOM.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

1. What is JSX?

JSX stands for JavaScript XML. It is an extension to JavaScript syntax that allows you to write HTML-like structure directly within your JavaScript files. Behind the scenes, build tools (like Babel or SWC) compile JSX into standard React.createElement() function calls.

// What you write in JSX:
const element = 

Welcome to Online CBT

; // What the compiler produces: const element = React.createElement("h1", { className: "title" }, "Welcome to Online CBT");

2. Core Rules of JSX Syntax

A. Every Component Must Return a Single Root Element

JSX must be enclosed within a single parent element. If you do not want to add unnecessary extra

nodes to the DOM tree, wrap them in a React Fragment (<>...):

function ExamHeader() {
  return (
    <>
      

NEET Mock Examination 2026

Duration: 180 Minutes | Total Marks: 720

); }

B. All Tags Must Be Explicitly Closed

Self-closing elements in HTML (such as , ,
,


) must always be closed with a forward slash in JSX:

Portal Logo


C. camelCase Attribute Naming

Because JSX is closer to JavaScript than HTML, attribute names use camelCase:

  • Use className instead of class (since class is a reserved keyword in JavaScript).
  • Use htmlFor instead of for in label elements.
  • Use tabIndex, readOnly, autoComplete, etc.

3. Embedding JavaScript Expressions with Curly Braces {}

You can embed any valid JavaScript expression (variables, function calls, arithmetic, ternary checks) inside JSX by wrapping it in curly braces {}:

function StudentBadge() {
  const studentName = "Rohan Verma";
  const score = 94;
  const maxScore = 100;

  return (
    

Candidate: {studentName.toUpperCase()}

Accuracy: {(score / maxScore) * 100}%

Status: {score >= 50 ? "Qualified" : "Disqualified"}

); }

4. Inline Styles in JSX

Inline styles in JSX are passed as JavaScript objects where CSS properties use camelCase rather than hyphens:

const headerStyle = {
  backgroundColor: "#1e3a8a",
  color: "#ffffff",
  padding: "16px 24px",
  borderRadius: "8px",
  fontSize: "20px"
};

function TopBanner() {
  return 
Active Exam Session
; }

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
Address Contact

+91 7877547686

E-mail

onlinecbtportal@gmail.com

Helpline Number

+91 7877547686


Click To Download
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat