Line breaks

Under normal circumstances there should be no need to insert line breaks into your web page. The web browser should be able to follow any instructions provided via your stylesheet to determine where and when to start a new line when displaying output on the screen. Most of the uses for line breaks in earlier versions of HTML have been replaced with stylesheet commands for specifying white-space settings and margins and padding.

The only time that line breaks need to be inserted in XHTML are where there absolutely must be a line break at a particular position. Two examples of where this would be the case are with poetry and computer code. In each of these cases the linebreak is a significant part of the actual content and not just a part of the page formatting.

Where such line breaks are a requirement of the content they can be easily inserted using the <br/> tag.

Note that the line break self closing. When used to provide content specific line breaks like this there should be no need to apply any stylesheet overrides to the default settings for this tag and so if you find such settings necessary you are probably misusing this tag to apply formatting rather than for its intended purpose. Therefore while there are a few attributes that can be added to a line break tag you should never need to use any of them.

Note that there is no space needed before the / that makes an XHTML tag self closing. The reason why people started adding a space there relates to writing XHTML that was to be initially served as HTML while waiting for all browsers to add support for XHTML. One browser that didn't support XHTML that was popular for a time after the XHTML standard was released was Netscape 4. While other browsers simply treat that / as an invalid character in HTML and ignore it, Netscape 4 treated it as a part of the tag or attribute immediately preceding it and would there fore treat that entire attribute or tag as invalid. By adding the space Netscape 4 would treat the / the same way as other browsers. Now that Netscape 4 is long dead there is no reason for the space before the / even when you are serving the page as HTML instead of as XHTML so that your page will display in Internet Explorer 8 (which is the last popular browser that doesn't support XHTML).

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate