Damiano
Damiano

Reputation: 459

What determines if an element needs a closing tag?

I was wondering what determines if an element needs a closing tag or not. For example, input, br and hr don't support being closed with </element> but their structure is simply <element/> (although I prefer just <element>) - with attributes if needed.

Also, how would I replicate this behaviour in a custom element?

Upvotes: 3

Views: 415

Answers (1)

Quentin
Quentin

Reputation: 943250

I was wondering what determines if an element needs a closing tag or not.

Their definition in the HTML specification.

but their structure is simply <element/>

The / is optional in HTML 5. It is only there for people who got used to the syntax when XHTML looked like the way forward.

Also, how would I replicate this behaviour in a custom element?

You can't. The custom element specification doesn't provide any means to make an end tag optional or forbidden.

Upvotes: 4

Related Questions