Table of Contents

About

In React, HTML elements are:

Example

with Jsx

In Jsx

  • A css class that we will apply to our HTML element
.blue { color: blue; }
const ourP = <p className="blue" style={{textAlign: 'center'}}>Hello World</p>;
  • The standard mandatory root DOM node (placeholder for React DOM manipulation)
<div id="root"></div>
  • Rendering of the ReactHTML component in the root div defined below
ReactDOM.render(
  ourP,
  document.getElementById('root')
);
  • Output:

with Pure Javascript

With createElement, the same example as above.

const ourP = React.createElement(
       'p' ,  // the type: the string equivalent of the HTML tag (ie h1, div, ...)
       {  
           className: "blue",
           style: {textAlign: 'center'}
       }, // props are the equivalent of HTML attributes
       ['Hello World'] // children are other react element or a string for a text node
)
  • Output:

Syntax

They start with a lowercase letter whereas the component (React Element created by yourself or a library) starts with an uppercase letter.

Ref

They are the only ones to be able to receive a ref directly to get the underlying DOM element. For component, you need to use React.forwardRef to make them ref aware.