xcdemon05
xcdemon05

Reputation: 716

Is there a "best way" to write line break tags?

I have always just written them as

<br>

but I've seen many other people instead include the closing tag

<br />

I've never noticed a difference between these two ways, but I'm wondering if there is some subtle difference that makes one better than the other.

Upvotes: 0

Views: 30

Answers (2)

dkatzel
dkatzel

Reputation: 31648

To be XHTML compliant all tags must be closed. The way to properly close a <br> tag is with the trailing slash <br/>

If all the tags are properly closed, not only is it XHTML compliant but it greatly simplifies parsing since you can treat the html file as XML so any XML parser can parse the file.

Upvotes: 0

Ahs N
Ahs N

Reputation: 8366

Both are the same.

Every opening tag should have a closing tag. But not all tag need data to be written between opening and closing tags, like <a> and <h1>. So the proper form is <br/>.

If you omit the slash, web browsers automatically assume its a syntax error and correct it for you when rendering. There are other such tags, example input and img tag among others, that have opening and closing tags 'two in one'. And forward slash is added automatically during rendering if omitted by the user.

Upvotes: 1

Related Questions