React JS: HTML basics

HTML for React (1/5)

reactjs
html
An introduction to HTML for React students, covering document structure, the most relevant tags, attributes and semantic layout.
Author

albertprofe

Published

Monday, November 16, 2026

Modified

Monday, November 16, 2026

1 Overview

📘 HTML HyperText Markup Language is the standard markup language for creating web pages. It describes the structure of a page as a tree of elements: “this is a heading”, “this is a paragraph”, “this is a link”, and so on.

React does not replace HTML: every React component ends up rendering HTML elements into the DOM. JSX is just HTML-like syntax inside JavaScript, so knowing HTML well is the first step to writing good JSX.


2 Why HTML before React?

When we write a component like this:

Hello.jsx
export default function Hello() {
  return <h1 className="title">Hello, students!</h1>;
}

the browser never sees JSX. React translates it and finally the DOM contains a plain <h1 class="title">. So:

  • the tags we use in JSX are HTML tags (div, p, ul, form, button…),
  • the attributes are (almost) HTML attributes (src, alt, href, type…),
  • the events we handle in React (onClick, onChange, onSubmit) are the browser’s HTML DOM events (see Events and the DOM).
HTML is the output of React

If you know which HTML you want in the browser, writing the JSX is easy. If you don’t, React only makes it harder.

3 HTML document structure

A minimal HTML5 document looks like this:

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My first page</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <h1>My first heading</h1>
    <p>My first paragraph.</p>

    <script src="app.js"></script>
  </body>
</html>
  • <!DOCTYPE html> tells the browser this is an HTML5 document.
  • <html> is the root element of the page.
  • <head> holds meta information, not shown on the page:
    • <meta charset>: character encoding (use UTF-8).
    • <meta name="viewport">: makes the page responsive on mobile.
    • <title>: the text in the browser tab (and in search results).
    • <link>: links external resources, mostly CSS stylesheets.
    • <script>: JavaScript, inline or from a file (src). It can also go at the end of <body>.
  • <body> contains everything visible: headings, paragraphs, images, links, tables, lists…

3.1 Elements, tags and empty elements

An element is a start tag, some content and an end tag:

<p>This is a paragraph.</p>
<!-- start tag ^      ^ end tag -->

Elements can be nested (an element inside another element), and that nesting is what builds the DOM tree.

Some elements have no content and no end tag: they are empty elements, like <br>, <img>, <input>, <meta> or <link>.

In JSX every tag must be closed

HTML accepts <br> and <img src="a.png">, but JSX does not. In React you must write <br /> and <img src="a.png" />.

4 The most relevant tags

4.1 Text

<h1>Main title</h1>          <!-- h1 ... h6: headings, h1 is the most important -->
<h2>Section title</h2>
<p>A paragraph with <strong>important</strong> and <em>emphasised</em> text.<br>
   And a line break.</p>
<hr>                          <!-- a thematic break (horizontal line) -->
  • Use one <h1> per page and keep headings in order (h1 → h2 → h3): search engines and screen readers use them to understand the page.
  • <strong> and <em> add meaning (importance, emphasis), not only bold or italic style.
  • Browsers ignore extra spaces and line breaks in the source: use <p> and <br>.

4.3 Lists

<ul>                <!-- unordered list (bullets) -->
  <li>HTML</li>
  <li>CSS</li>
</ul>

<ol>                <!-- ordered list (numbers) -->
  <li>Learn HTML</li>
  <li>Learn React</li>
</ol>

Lists are everywhere in React: a todo list, a menu, a list of products. Later you will render them with array.map().

4.4 Tables

<table>
  <thead>
    <tr><th>Name</th><th>Role</th></tr>
  </thead>
  <tbody>
    <tr><td>Ada</td><td>Frontend</td></tr>
    <tr><td>Linus</td><td>Backend</td></tr>
  </tbody>
</table>
  • <tr> is a table row, <th> a header cell and <td> a data cell.
  • <thead> and <tbody> group the header rows and the body rows.

4.5 Containers: div and span

<div class="card">
  <h3>Card title</h3>
  <p>Some text with a <span class="highlight">highlighted</span> word.</p>
</div>
  • <div> is a block-level element: it always starts on a new line and takes the full width.
  • <span> is an inline element: it only takes the width it needs and stays inside the text.
  • Neither has any meaning: they are generic boxes to group content and style it with CSS.

4.6 Semantic elements (layout)

Semantic elements are elements with meaning: the name tells the browser and the developer what the content is. Instead of <div id="nav"> or <div class="footer">, HTML5 gives us:

layout.html
<body>
  <header>
    <h1>My shop</h1>
    <nav>
      <a href="/">Home</a> | <a href="/products">Products</a>
    </nav>
  </header>

  <main>
    <section>
      <h2>New products</h2>
      <article>
        <h3>Keyboard</h3>
        <p>Mechanical keyboard, 45 €.</p>
      </article>
    </section>
    <aside>Offers of the week</aside>
  </main>

  <footer>© 2026 My shop</footer>
</body>
Element Meaning
<header> Introductory content: logo, title, navigation
<nav> A block of navigation links
<main> The main content of the page (only one per page)
<section> A thematic group of content, usually with a heading
<article> Independent, self-contained content (a post, a product)
<aside> Content aside from the main content (a sidebar)
<footer> Footer of the page or of a section: author, copyright, links

In React, a page layout is usually split into components with the same names: <Header />, <Nav />, <Main />, <Footer />. Each component returns its semantic HTML element.

5 Attributes

Attributes give extra information about an element. They always go in the start tag as name="value".

Most common HTML attributes
Attribute Used on What it does
id any element A unique identifier in the page (for CSS, JS, labels)
class any element One or more class names, shared by many elements (CSS)
style any element Inline CSS: style="color:red; font-size:20px"
href <a>, <link> URL of the link or resource
src <img>, <script> Path of the image or script
alt <img> Alternative text for the image
type <input>, <button> Kind of input or button
name form fields Key of the field when the form is sent
value form fields Current or initial value of the field
lang <html> Language of the page

6 Summary

HTML tags cheat sheet
Group Tags
Structure <!DOCTYPE html>, <html>, <head>, <body>, <meta>, <title>, <link>, <script>
Text <h1>–<h6>, <p>, <strong>, <em>, <br>, <hr>
Links/media <a>, <img>
Lists <ul>, <ol>, <li>
Tables <table>, <thead>, <tbody>, <tr>, <th>, <td>
Containers <div> (block), <span> (inline)
Semantic <header>, <nav>, <main>, <section>, <article>, <aside>, <footer>

Forms have their own article: HTML forms.

HTML for React

7 References

Back to top