Skip to main content

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 renders into the browser platform
JSX
Declarative UI source
React element descriptions
HTML / SVG DOM nodes
Layout, events, forms, accessibility, rendering

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} />
JSX prop names usually follow DOM property conventions
HTML class
โ†’ className
HTML for
โ†’ htmlFor
HTML tabindex
โ†’ tabIndex

ARIA 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 }} />
Normal JSX and raw HTML have different security contracts
SAFE DEFAULTNormal JSX text

Value โ†’ React escaping โ†’ DOM text/content

TRUST BOUNDARYdangerouslySetInnerHTML

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.

Rich-text editors need one clear DOM owner
React-controlled children
React computes and owns child DOM.
Editable/browser/library-owned DOM
Browser/editor mutates child DOM directly.

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โ€‹

A custom element may expose both markup attributes and JavaScript properties
MARKUP CHANNELAttribute

Serialized in markup ยท string-oriented ยท inspectable as an HTML attribute

OBJECT CHANNELProperty

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} />;
}
A React wrapper is useful when it improves the application-facing contract
Application props/events
React wrapper
Prop naming ยท event mapping ยท refs ยท accessibility defaults ยท property assignment
Custom element API

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.

Two safe integration shapes
React owns outer surface

React container
โ†’ dedicated ref node
โ†’ third-party library exclusively owns inside that node

External system owns outer surface

External container
โ†’ designated child mount point
โ†’ React root/portal exclusively owns that child surface

Avoid both systems mutating the same child nodes.

Integration decisionโ€‹

Who should own this DOM region?
Plain UI React can model declarativelyLet React own it
Imperative library needs a canvas/map/editor surfaceGive it one dedicated ref-owned island
Legacy/CMS system owns the page regionMount a React root/portal into a designated child surface
Both need to mutate the same nodesRedesign the boundary โ€” shared mutation is unstable

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โ€‹

React DOM is an adapter to the browser, not a replacement for it
1Use semantic JSX
2React DOM maps it to platform nodes
3Respect trust + ownership boundaries
4Let the browser provide native behavior

Referencesโ€‹