Map HTML attributes to JSX props
Translate HTML attributes into JSX props
For built-in React DOM elements, JSX attributes are passed as props: values that describe the element. Many use JavaScript-friendly names, such as className and htmlFor. Names such as aria-label and data-topic retain hyphens. Check the React DOM reference rather than mechanically renaming every attribute.
export default function App() { return ( <main className="reading-card"> <h1>Find a book</h1> <label htmlFor="book-query">Book title</label> <input id="book-query" type="search" /> <button type="button" disabled={true}>Unavailable</button> </main> );}The expected interface has a heading, a search field labelled Book title and a disabled button. The label htmlFor matches the input id, allowing the browser to associate them. className becomes the CSS class on main; without a matching stylesheet, it does not change the visual design. disabled receives a Boolean true, so the button is disabled. disabled="false" passes a string, not Boolean false. For an enabled button omit disabled or pass false.
Use an object for inline styles
export default function App() { const badgeStyle = { color: '#243b53', fontWeight: 'bold', padding: 8 }; return <p style={badgeStyle}>Library open</p>;}The expected paragraph displays bold, dark-blue text with 8 pixels of padding. style accepts a JavaScript object. The braces enter JavaScript; the object literal defines style values. Here the CSS property font-weight becomes fontWeight. React interprets numeric padding in pixels; some properties such as opacity and fontWeight are unitless. Use a CSS class for static design rules when practical. The string style syntax from HTML is not the React DOM style prop contract.
Pass several known attributes with spread
export default function App() { const searchAttributes = { id: 'author', type: 'search', placeholder: 'Name' }; return ( <> <label htmlFor="author">Author</label> <input {...searchAttributes} placeholder="Author name" data-topic="books" /> <button type="button" aria-label="Clear search">Clear</button> </> );}The search field receives id and type from the object. Its placeholder becomes Author name because the later explicit prop overrides the earlier spread value. The accessible name comes from its associated label, not the placeholder. The data attribute stores a small metadata value. The button demonstrates an ARIA label; it does not clear anything yet, because event handling is taught in Chapter 9. Avoid spreading unreviewed objects onto DOM elements: select intended values instead.
Common mistakes
Do not replace a real label with only a placeholder or CSS class. Keep IDs unique in the document; these single-instance examples have deliberately chosen IDs. Avoid using dangerouslySetInnerHTML to display ordinary text. For HTML-like user content, normal JSX text is the safe default; handling intentionally trusted rich HTML is a separate security topic. Do not infer accessibility compliance from correct syntax alone.
Practice
Convert a small HTML field into JSX and explain the label, Boolean disabled value, and style object. The next chapter builds reusable components from these markup foundations.