How to fix: End tag for element "div" which is not open

Most Likely Cause and Fix

Your markup contains a closing tag in the form of <div /> that is lacking a preceding opening tag such as <div … >.

Either:

The relevant element was inadvertently closed too soon when another element was intended to be closed:

<div>
  <span>
    Foo
  </div> <!-- div is closed where when span should have been closed -->
</div> <!-- This will cause an error when the div is closed again -->
        

Or:

The closing tag <div /> has inadvertently been included twice:

<div>
  <span>Foo</span>
</div>
</div> &lt!-- closing div tag included twice by mistake -->

What This Error Means

Elements in HTML have a start and an end, with sometimes something in the middle:

<p> <!-- start -->
  Foo  <!-- middle -->
</p> <!-- end -->

When you include an element in your markup you should, as you might expect, begin with the start, include any content in the middle where relevant and finish with the end.

To have the closing tag for an element that does not have a start tag is to produce invalid HTML and that is exactly what this error is telling you.

How To Fix It

There is no general fix for this type of problem as how to solve it depends on the context in which the error occurs.

Use the line and column number in the specific error message you encountered to find the position in your markup that is causing the error.

Take a look at the elements in your markup that come before the line that is causing the error to give context.

There are some common causes for this type of error, although which, if any, applies to you depends on the context in which the error occurs.

The relevant element was inadvertently closed too soon

The element to which the error relates contains one or more other elements and was intended to be as follows:

<div>
  <span>
    Foo
  </div>
</div>

When intending to close the contained <span> element, you closed the parent element by mistake, producing invalid markup:

<div>
  <span>
    Foo
  </div> <!-- div closed by mistake when intended to close span -->
</div> <!-- this div close tag now has no matching open tag which causes the error -->
    

Closing tag included twice by mistake

Your markup contains a straightforward element similar to:

<span>
  Foo
</span>
    

When closing this element, the closing tag was added twice instead of just once, resulting in invalid markup:

<span>
  Foo
</span>
</span> <!-- close tag included twice by mistake -->

Discuss, Comment and Improve

Did this help you? Can this page be improved? Let us know!

comments powered by Disqus