🎓 A1Learner
🔍
0 of 50 lessons completed

Nesting Elements

Nesting elements means placing tags inside other tags. The outer tag holds the inner tags like a box holds items.

Two tags in a box

The div holds a heading and a paragraph.

return (
  <div>
    <h1>Welcome</h1>
    <p>React is ready.</p>
  </div>
)

Example

export default function App() {
  return (
    <div>
      <h1>Welcome</h1>
      <p>React is ready.</p>
    </div>
  )
}

Key points

  • A div tag is a plain box that groups other tags.
  • Inner tags sit between the opening tag and the closing tag of the outer tag.
  • Nesting keeps related markup together in one place.
  • The outer tag is the one root element of the return statement.

In this example, App returns a div. The div holds a heading and a paragraph. The heading reads Welcome. The paragraph reads React is ready.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What does nesting elements mean?