Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML ID attribute in close tag?

Tags:

html

css

Is this code okay, where I ID a close div:

<html>
<body>
<div id="main">

</div id=main">
</body>
</html>
like image 638
Jagger Avatar asked Feb 13 '26 15:02

Jagger


2 Answers

No. The id attribute should only be in the opening tag.

If you're doing this for readability, you might want to use HTML comments and tabified source:

<html>
    <body>
        <div id="main">

        </div>
        <!-- close main div -->
    </body>
</html>
like image 74
Polynomial Avatar answered Feb 15 '26 04:02

Polynomial


It's invalid: The validator will output

Line x, Column y: End tag had attributes.

If you want to do this to avoid confusion from multiple closing tags, just use a comment to clarify which tag belongs to which element:

</div> <!-- #main -->
like image 44
Pekka Avatar answered Feb 15 '26 05:02

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!