#1 India's Top IT Training Institute
×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
Mentors

Mentors

Meet the industry experts who train and guide you through your course.

Read More →
Free Resources

Free Resources

Free tutorials, interview questions, tools and calculators to help you learn.

Explore →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
JSX

Working with HTML

JSX lets you write markup inside JavaScript that looks almost exactly like HTML, but it is not HTML. Each tag becomes a call that creates a React element, and attributes become properties of a JavaScript object. That is why a handful of rules differ from what you know from plain HTML. Learning these differences early saves you from confusing warnings and markup that silently does not work.

Attribute names follow JavaScript

Because class and for are reserved words in JavaScript, JSX uses className and htmlFor. Most other multi-word attributes and all event handlers are written in camelCase: tabIndex, maxLength, onClick, onChange. Two exceptions keep their dashes: data-* attributes and aria-* attributes stay exactly as in HTML.

function ProfileCard({ user }) {
  return (
    <>
      {/* A fragment groups siblings without adding a wrapper div */}
      <img src={user.avatar} alt={user.name} className="avatar" />
      <label htmlFor="bio">Bio</label>
      <textarea id="bio" defaultValue={user.bio} maxLength={200} />
      <p
        className="status"
        style={{ color: user.online ? 'green' : 'gray', fontSize: '0.9rem' }}
        data-user-id={user.id}
        aria-live="polite"
      >
        {user.online ? 'Online' : 'Offline'}
      </p>
      <br />
    </>
  );
}

Every tag must be closed

HTML forgives unclosed tags like <br>, <img> and <input>. JSX does not. Void elements need a self-closing slash, as in <br />, and any component without children can be written the same way, such as <Spinner />. Forgetting the slash produces a compile error pointing at the next line, which can be puzzling at first.

One parent per return

A component returns a single expression, so two sibling elements must be wrapped. A div works, but it adds an extra node that can break CSS layouts such as flex rows or tables. A fragment, written <>...</>, groups siblings without adding anything to the page. Use the longer <Fragment key={...}> form when you need a key in a list.

Styles are objects, not strings

The style attribute takes a JavaScript object. CSS property names become camelCase, such as backgroundColor, and values are usually strings. The double braces in style={{ ... }} are not special syntax: the outer pair switches into JavaScript, and the inner pair is the object literal. A plain number is treated as pixels for most size properties, so { padding: 8 } means 8px.

Comments and other surprises

HTML comments do not work in JSX. Write {/* comment */} instead. Form fields also behave differently: in JSX, value on an input or textarea makes it controlled by React, while defaultValue sets only the starting text. Placing text between <textarea> tags, as you would in HTML, is not how React sets its content.

Finally, React escapes any string you place in braces, so {"<b>hi</b>"} shows the tags as text. That protects against injected scripts. Rendering raw HTML requires dangerouslySetInnerHTML, and its name is a deliberate warning to use it only with sanitised content.

Quick reference

  • class becomes className; for becomes htmlFor.
  • Close every tag, including <img /> and <input />.
  • Wrap siblings in a fragment.
  • Pass style an object with camelCase keys.
  • Write comments as {/* ... */}.

Ready to master real-world web development?

Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.

Explore Course