Home / Learn React / HTML Elements and Props in JSX
HTML Elements and Props in JSX
In JSX you write normal HTML elements, but attributes follow JavaScript names: className, htmlFor, camelCase events and a style object.
Theory in plain words
What it is
React DOM elements are the lowercase tags such as div, input, img. React supports the standard HTML and SVG tags, with attribute names changed where JavaScript has a conflict.
Why we use it
JSX is JavaScript, so words like class and for are reserved. Using the right names avoids silent bugs, and the object form of style makes dynamic styling simple.
How it works
React turns each element into a DOM node and sets properties from your props. Event props such as onClick use React's synthetic event system. Unknown lowercase props pass through to the DOM element.
Where it is used
- Every React screen: layouts, forms, media, tables, SVG icons
The button is disabled until both the checkbox and name are filled. value on select and textarea works like on input in React.
| Element | Typical props | Note |
|---|---|---|
a | href, target, rel | Add rel="noopener noreferrer" with target="_blank". Use Link from a router for internal pages. |
img | src, alt, width, height, loading | Always set alt and size to avoid layout jumps. |
button | type, onClick, disabled | Set type="button" when not submitting. |
input | value, onChange, checked, type | Use defaultValue for uncontrolled inputs. |
textarea, select | value, onChange | Value is a prop, not text between tags. |
label | htmlFor | Links the label to an input id. |
ul, li | key | Keys go on the outer element in map. |
svg | viewBox, strokeWidth, fillRule | SVG attributes use camelCase: stroke-width becomes strokeWidth. |
dialog, details | open, onToggle | Native, accessible building blocks. |
Boolean attributes and dangerouslySetInnerHTML
dangerouslySetInnerHTML inserts raw HTML and can create XSS holes. Use it only with HTML you have cleaned with a library such as DOMPurify.Quick quiz
1. JSX name for the HTML class attribute?
class is reserved in JavaScript.
2. How do you write inline style in JSX?
An object with camelCase keys.
3. Which attribute links a label to an input?
htmlFor.
Common questions
JSX name for the HTML class attribute?
className. class is reserved in JavaScript.
How do you write inline style in JSX?
style={{ color: "red" }}. An object with camelCase keys.
Which attribute links a label to an input?
htmlFor. htmlFor.