DEV Community

Cover image for Difference between JSX and HTML
Stephanie Opala
Stephanie Opala

Posted on • Edited on

8 2

Difference between JSX and HTML

One of the requirements when you start to learn React is learning JSX. So what is JSX? This is a JavaScript syntax extension. When you are new to it and have a glance at the syntax for the first time, it looks like a mixture of both JavaScript and HTML. Here is an example;

const heading = <h1>Hello world</h1>;
Enter fullscreen mode Exit fullscreen mode

JSX is popularly used in React and in this post, I will be highlighting the key differences between JSX and HTML syntax.

Use of className instead of class attribute

In JSX we use className attribute whereas in HTML we use the class attribute. This is because JSX is transpiled into JavaScript and class is a reserved word in JavaScript.
JSX
<div className = "container"></div>
HTML
<div class = "container"></div>

Self closing tags

Self-closing tags in JSX must have the forward slash whereas the forward slash is optional in the HTML self-closing tags.
JSX
<img src="#" />
<br/>

HTML
<img src="#" >
<br>

Event listeners

Event listeners in JSX are written in camelCase, for instance, onClick whereas in HTML, they are written in lowercase for instance, onclick

These are some of the key differences. You can have a look at the React documentation if you would like to learn more about JSX.
Happy coding!

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay