Skip to content

JSX element not properly closed

Quick summary

Your JSX has an unclosed element — the transpiler cannot parse the JSX and reports a syntax error at the opening tag.

Why this happens

  • An opening JSX tag like <div> is missing its corresponding </div> closing tag

  • A self-closing element like <img> is missing the trailing slash: should be <img />

  • Nested JSX tags are closed in the wrong order, leaving an inner element unclosed

Minimal example

✗ Broken code
function App() {
  return (
    <div>
      <p>Hello World
    </div>
  ); // </p> missing
}
✓ Fixed code
function App() {
  return (
    <div>
      <p>Hello World</p>
    </div>
  );
}

Adding the missing </p> closing tag makes the JSX well-formed and parseable by the transpiler.

How to diagnose

  • Read the compiler error message which usually points to the line of the unclosed tag

  • Check that every opening JSX tag has a matching closing tag or is self-closed with />

  • Use an editor with JSX syntax highlighting to visually identify mismatched tags

How to fix

  • Add the missing closing tag for the unclosed element

  • Add the self-closing slash to void elements: <img src='...' /> instead of <img src='...'>

  • Reorder the closing tags to match the nesting structure of the opening tags

How to prevent

  • Use an editor with JSX/TSX syntax support that highlights mismatched tags in real time

  • Format your JSX with Prettier which can detect and surface unclosed tag issues

Related Resources

Related Glossary

Related Lessons

← Back to language