Void Elements in HTML

What’s the difference between ending a void element with

<link rel="stylesheet" href="./styles.css" />

or ending it with

<link rel="stylesheet" href="./styles.css" >
1 Like

First one is from old version of html called XHTML and the second one is from new version of html called HTML5.

1 Like
1 Like

Thank you, I was just confused because the curriculum uses the first one, but my web design teacher says that the second is correct.

1 Like

They are both “correct” in some sense.

  • The browser ignores the slash.

  • Prettier adds it by default.

  • React developers often add it out of habit, or because they prefer the formatting.

  • Most HTML validators will warn about it, but will still validate the HTML.

Trailing slash on void elements has no effect and interacts badly with unquoted attribute values.

1 Like

Thank you!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.