React DOM components, custom elements, and SVG
React DOM translates React element descriptions into browser HTML/SVG nodes. The browser still owns semantics, layout, accessibility, native controls, network behavior, and low-level DOM rules.
The platform mental modelโ
React does not replace HTML semantics. Prefer native browser behavior whenever it already solves the interaction correctly.
Built-in elements and component namesโ
<div />
<button />
<svg />
Lowercase JSX names are browser elements. Capitalized names are React components:
<Button />
DOM prop conventionsโ
<label htmlFor="email">Email</label>
<input id="email" className="field" tabIndex={0} />
classNamehtmlFortabIndexARIA and data attributes keep their normal names:
<button aria-expanded={open}>Menu</button>
<div data-user-id={user.id} />
Use JavaScript values directly rather than stringifying everything:
<button disabled={isSaving}>Save</button>
<input maxLength={120} />
Eventsโ
<button onClick={handleClick}>Save</button>
<input onChange={handleChange} />
<div onPointerMove={handlePointerMove} />
Event props use camelCase, with capture variants such as onClickCapture.
React's documented event behavior is the contract to program against. Do not assume every browser event maps one-to-one to browser bubbling details.
Stylingโ
<div
style={{
width: 320,
opacity: isDisabled ? 0.5 : 1,
}}
/>
Use inline styles for genuinely dynamic values. Static styling is usually easier to maintain through classes.
Raw HTML is a trust boundaryโ
<div dangerouslySetInnerHTML={{ __html: html }} />
Value โ React escaping โ DOM text/content
HTML string โ bypass normal escaping โ browser parses markup
Sanitization and content policy become your responsibility.
Never feed unsanitized user or CMS HTML into this API.
<div dangerouslySetInnerHTML={{ __html: userComment }} />
When raw HTML is required, sanitize at a trusted boundary with a maintained sanitizer and explicit content policy.
Children and dangerouslySetInnerHTML are mutually exclusive: React needs one clear owner for an element's contents.
contentEditable creates competing ownershipโ
<div contentEditable />
A browser-editable subtree changes the DOM directly while React normally expects to derive child DOM from JSX.
Do not casually combine both ownership models. suppressContentEditableWarning exists for libraries that intentionally take responsibility; it does not repair an unclear architecture.
Hydration warning escape hatchโ
<time suppressHydrationWarning>
{clientSpecificTime}
</time>
Use suppressHydrationWarning only for narrow intentional differences. It suppresses a warning; it does not make a nondeterministic server/client render correct.
DOM refsโ
const inputRef = useRef(null);
<input ref={inputRef} />
After commit, the ref points to the DOM node. React 19 also supports callback-ref cleanup:
<div
ref={node => {
observe(node);
return () => unobserve(node);
}}
/>
Custom elements
Web Components expose browser-native custom tags such as:
<user-avatar user-id="42" />
Attributes and properties are different channelsโ
Serialized in markup ยท string-oriented ยท inspectable as an HTML attribute
Set on the element instance ยท can hold arbitrary JavaScript values ยท follows the custom element contract
String-oriented example:
<status-badge state="online" />
Rich JavaScript value:
<chart-view data={points} />
Read the Web Component's API instead of assuming every value should be serialized as an attribute.
A custom element that expects rich property values should establish a stable property surface on its instance.
class ChartView extends HTMLElement {
constructor() {
super();
this.data = undefined;
}
}
Custom eventsโ
<voice-player
onspeak={event => {
console.log(event.detail.message);
}}
/>
When integrating a third-party custom element, verify event naming, case sensitivity, detail shape, bubbling/composed behavior, and cleanup requirements.
Wrapper components normalize boundariesโ
function VoicePlayer({ onSpeak, ...props }) {
return <voice-player onspeak={onSpeak} {...props} />;
}
Do not wrap automatically; wrap when the adapter creates a clearer or safer contract.
SVG in React
function CheckIcon() {
return (
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M5 12l4 4L19 6" />
</svg>
);
}
SVG is still browser SVG, expressed through JSX.
Decorative graphic:
<svg aria-hidden="true" focusable="false">...</svg>
Meaningful graphic:
<svg role="img" aria-labelledby="chart-title">
<title id="chart-title">Monthly revenue</title>
...
</svg>
The accessibility pattern depends on whether the graphic communicates information.
Prefer native semanticsโ
Prefer:
<button>Save</button>
over rebuilding a button from a generic element:
<div role="button" tabIndex={0}>Save</div>
Native controls already provide keyboard, semantic, form, focus, and accessibility behavior.
DOM ownership boundariesโ
React assumes it owns the DOM subtree it renders. Bugs appear when another system mutates the same nodes independently.
React container
โ dedicated ref node
โ third-party library exclusively owns inside that node
External container
โ designated child mount point
โ React root/portal exclusively owns that child surface
Avoid both systems mutating the same child nodes.
Integration decisionโ
Security checklistโ
- keep untrusted content as normal JSX text when possible;
- sanitize raw HTML;
- validate URLs used in navigation/resource contexts;
- treat custom-element event payloads as untrusted input;
- preserve semantic HTML;
- fix hydration errors rather than hiding them broadly;
- avoid direct DOM mutation of React-owned children.
Exerciseโ
Build a page containing a semantic form, decorative and meaningful SVGs, a custom <rating-stars> element behind a React wrapper, a sanitized CMS renderer, and a third-party chart that owns only one dedicated DOM island.
For each piece, document who owns the DOM and where the trust boundary lives.
Interview questionsโ
Junior: Why does JSX use names such as className and htmlFor?
Mid-level: Why is dangerouslySetInnerHTML a security boundary?
Senior: How would you integrate React, a Web Component, and an imperative DOM library without creating overlapping DOM ownership?
Summaryโ
Referencesโ
- https://react.dev/reference/react-dom/components/common
- https://react.dev/reference/react-dom/components
- https://react.dev/reference/react-dom/components/form
- https://react.dev/reference/react-dom/components/input
- https://react.dev/reference/react-dom/components/select
- https://react.dev/reference/react-dom/components/textarea