Publishers of technology books, eBooks, and videos for creative people

Home > Articles > Web Design & Development > HTML/XHTML

  • Print
  • + Share This
This chapter is from the book

Creating a Line Break

Browsers automatically wrap text according to the width of the block or window, creating new lines as necessary. While you can start a new paragraph with the p tag (see page 66), you can also create manual line breaks anywhere you like.

The br tag is perfect for poems or other short lines of text that should appear one after another without a lot of space in between.

Figure 3.18 Figure 3.18 I've created a new division at the top of the page that can serve as a table of contents. There will be three lines (thanks to the br tag) with the minimum of space between each one.

To insert a line break:

Type <br /> where the line break should occur. There is no separate closing br tag.

Figure 3.19 Figure 3.19 Remember that the returns in your code are always ignored. This code is equivalent to that shown above in Figure 3.18.

Tips

  • The closing slash (/) is only required in XHTML documents to satisfy the rule that all elements be properly closed (see page 36). Make sure there is a space between br and the slash. You may omit the slash entirely in HTML documents, though it does no harm to include it.

  • You can use multiple br tags to create extra space between lines or paragraphs.

    Figure 3.20 Figure 3.20 The br element starts the subsequent elements on a new line.

  • Styles can help you control the space between lines in a paragraph (see page 164) and between the paragraphs themselves (see pages 188 and 189). There are also a slew of non-standard and deprecated methods.

  • The br tag used to be used with the deprecated clear attribute to control text that is wrapped around images (see page 112). Its function has been replaced by the CSS clear property (see page 195).

  • The CSS white-space property is great for maintaining original page breaks (see page 170). Also see page 358 for details on the non-standard nobr element.

  • + Share This
  • 🔖 Save To Your Account