<br> Creating Line BreaksThe <br> element is an empty element that inserts a line break into text. Because this element is empty, you use it like this in XHTML: <br /> . This element is supported in XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, and XHTML 1.1. Here are the attributes of this element:
This element does not support any XHTML events. You use the <br> element to arrange the text in a document by adding a line break, making the browser skip to the next text line. This element is an empty element, so you use it like this: <br /> . This usage actually does not cause any problems in the major browsers, and the fact that those browsers are able to handle empty elements with the usual XML /> closing characters is one of the reasons that XHTML actually works as it should in HTML browsers. In fact, you can also insert line breaks as <br></br> , but that usage is confusing to some browsers and XML validators. Here's an example; in this case, I'm using <br> elements to introduce line breaks and a <p> element to create a new paragraph: Listing ch16_11.html<?xml version="1.0"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title> Using the <br> and <p> Elements </title> </head> <body> <center> <h1> Using the <br> and <p> Elements </h1> </center> This is a line of text. <br /> Using a line break skips to the next line. <p style="font-weight: bold"> This is a line of bold text in a paragraph. <br /> Here's a new line of text in the same paragraph. </p> </body> </html> The results of this code appear in Figure 16-9. As you can see, inserting a <br> element makes the browser move to the next line of text. Figure 16-9. Using line breaks and paragraphs in Netscape Navigator.
|