Forum Moderators: open

Message Too Old, No Replies

Markup question

Regarding a technique I'm not familiar with

         

Noisehag

8:33 pm on May 7, 2004 (gmt 0)

10+ Year Member



Something I have seen a lot but have no clue what the purpose is:

<br /> instead of <br>

Old or new syntax? Is it needed?

Thanks

sned

8:46 pm on May 7, 2004 (gmt 0)

10+ Year Member



I think this is for XHTML standards. Everything has to have a / at the end if it doesn't have an end tag. <hr /> <img src="" /> .. etc.

DrDoc

8:47 pm on May 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<br /> is XML style for <br>
You probably saw this on an XHTML page, which is a hybrid and mix between HTML and XML (basically, XML compatible HTML... still remaining essentially HTML).

XML requires a closing tag for all elements. Certain elements (<br>, <hr>, <img>, etc) do not have "closing tags" as defined by HTML. While <br></br> would be syntactically correct according to XML, it does not make much sense on a Web page (how is a browser supposed to interpret something like: <br>stuff</br> or <img>foobar</img>). To cause less confusion, and make more sense, it's been agreed that XML compatible HTML should use the shorthand closing tag as defined in the XML standard. Thus, <br> becomes <br/>, <img> becomes <img/>, etc. This, however, causes problems in certain browsers. To avoid these problems, a space is added before the slash. So, now we have <br /> and <img /> etc. That's still XML compatible, and now also works in browsers that are not XML compatible.

So, what are you supposed to use? Well, if it's an HTML page -- keep using <br> the way you are used to. However, if you are using XHTML the correct syntax is <br />.

What about elements that do not require a closing tag in the HTML recommendation (such as <p>, <tr>, <td>)? It's good practise to still use the proper closing tag, even if the HTML recommendation does not "require" it. In XHTML it's a requirement.

Noisehag

8:55 pm on May 7, 2004 (gmt 0)

10+ Year Member



Wow, thanks for the great responses.

I'm pretty antique when it comes to html coding and have never used closing tags for anything that didn't require it (28k connections still linger in the back of my mind I guess). Suppose I should start getting into the habit to help prepare myself for future changes.

sniffer

6:01 am on May 8, 2004 (gmt 0)

10+ Year Member



so would it be advisable to start creating HTML pages that are XML compliant, even if you dont use XML now, but may do so in the future?

mofo

4:04 pm on May 8, 2004 (gmt 0)

10+ Year Member



Hello

You can write HTML 4.01 as long as it is valid. XHTML is not so different from HTML, so you shouldn't have problems changing to XHTML.