CHAPTER 09 · HTML

Paragraphs, spaces and breaks: make text easy to read

The way you arrange lines in your editor is not always the way text appears in the browser. This chapter explains ordinary paragraphs, collapsed spaces, intentional line breaks, topic breaks and text whose spacing really should be preserved.

Download example files (ZIP)

What you will learn

  • Use a paragraph for one connected piece of text.
  • Predict normal whitespace handling without calling it deletion of the source.
  • Choose p, br, hr or pre for the right reason.
  • Keep headings and other large structures outside paragraphs.
  • Avoid spacing a page with empty paragraphs or repeated breaks.

A paragraph groups a thought

A paragraph contains a connected piece of text. For example, one paragraph might explain where a study meeting happens, while another explains what to bring. In HTML, use p around each paragraph.

HTML fragment — part of a document
<p>The study meeting starts at 3 pm in Room 6.</p>
<p>Bring the example you want to explain.</p>

Browsers normally place paragraphs on separate lines with some margin around them. Those are default presentation rules, not a guarantee of one exact blank line or fixed spacing on every device. CSS can change the appearance later.

Source lines and displayed lines are different

Whitespace is a name for spaces, tabs and line-break characters in text. Under normal browser styling, runs of ordinary whitespace are usually collapsed when the text is displayed. That means many typed spaces may appear as a single space in ordinary paragraph flow.

HTML fragment — part of a document
<p>Read    one
question before writing.</p>

The ordinary displayed text reads Read one question before writing. The source still contains the extra spaces and newline; the browser has not edited the saved file. It is applying text-display rules.

The line may wrap onto more than one screen line if the available width is narrow. Wrapping means moving text onto the next visible line when it no longer fits. It is not the same as the author inserting a br.

Complete example: normal text and preserved spacing

text-spacing.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Text Spacing Practice</title>
</head>
<body>
  <h1>Follow the practice steps</h1>
  <p>Read    one
question before writing.</p>
  <p>The browser chooses line wrapping from the available width.</p>
  <pre>Read
  Try
    Check</pre>
</body>
</html>
Browser previewDocument title: Text Spacing Practice

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.

Compare the first paragraph with pre. The paragraph follows normal spacing rules. Pre stands for preformatted text, where spaces and line breaks are meaningful and are normally preserved. The three lines and their indentation should remain visible there.

The pre example is a small text exercise, not a recommendation to align an entire website with spaces. Long preformatted lines can overflow a narrow screen. Use real layout tools such as CSS for page arrangement.

Use br for an intentional break within the same content

Br requests a line break without starting another paragraph. It is useful where the line division belongs to the content, such as a short postal address or lines of a poem.

HTML fragment — part of a document
<p>Peer learning desk<br>Room 6<br>Second floor</p>

This is one paragraph with three deliberately separated lines. Br is a void element, so it has no content or closing tag in HTML.

Do not press Enter in the editor and assume that it requests the same break in an ordinary paragraph. Also, do not place a br after every visual line of a long paragraph; the browser should be able to wrap ordinary text for different screen widths.

Use hr for a change of topic

Hr represents a thematic break: a change of subject within the content. Browsers often display it as a horizontal rule. It is not simply a command to draw any decorative line you want.

HTML fragment — part of a document
<p>The desk is open on Tuesday.</p>
<hr>
<p>For lost items, contact the reception desk instead.</p>

Here, the notice changes from learning help to a different service. Hr sits between the paragraphs. It must not be placed inside p as if it were just another word. Like br, it is a void element.

If you need a purely decorative border around a card, use CSS rather than adding a thematic break with no change in topic.

Choose the kind of text boundary
  1. 1p: another connected thought
  2. 2br: meaningful break within content
  3. 3hr: a change of topic
  4. 4pre: preserve meaningful spacing

Use CSS later for decorative gaps and borders. Do not arrange a page with many empty paragraphs or repeated line breaks.

A second complete example: two kinds of information

desk-notice.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Peer Learning Desk Notice</title>
</head>
<body>
  <h1>Peer learning desk</h1>
  <p>Find us here:<br>Room 6<br>Second floor</p>
  <hr>
  <p>Lost-item enquiries belong at reception.</p>
</body>
</html>
Browser previewDocument title: Peer Learning Desk Notice

This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.

The address uses br because those line divisions are part of the location text. Hr separates a different kind of enquiry. The paragraph after it is still an ordinary paragraph, not content inside hr.

If the source has an h1 or hr inside p, a browser may close the paragraph automatically before that element. That is one reason the inspected document structure can differ from what a learner thought they wrote. Keep those elements as siblings in this example.

Empty paragraphs do not create a good layout

Do not add several empty p elements or many br elements merely to push a button lower down the page. The apparent gap may change with fonts, screen width and other styles. It also adds meaningless structure for readers and tools.

Use separate paragraphs when the writing contains separate thoughts. Use CSS margin and padding for deliberate visual spacing. We will introduce those CSS ideas later; you do not need to learn them to write a clear document now.

Do not use old paragraph attributes such as align to centre text in new pages. Modern presentation belongs in CSS. We will identify older techniques when they appear in existing code and explain their replacements.

A preview of non-breaking spaces

You may see &nbsp;, a character reference representing a non-breaking space. A character reference is a written way to represent a character in HTML. This space can be useful when a particular pair of words or symbols should stay together.

It is not a sensible tool for placing columns, indenting whole sections or generating a large blank area. We will cover character entities properly in Chapter 13. At this stage, focus on using real paragraphs and breaks for their intended jobs.

Problem and solution: a location becomes one long line

Problem: a student writes a room and floor on separate source lines inside p, but they appear together in the browser.

Solution: decide whether the content really needs fixed line divisions. For a short location, insert br between the parts. For ordinary explanatory prose, keep a normal paragraph and allow the browser to wrap it.

Do not turn the whole page into pre just to preserve two location lines. Pre changes the whitespace behaviour of all of its content and may create unnecessarily wide text.

Common mistakes and useful tips

  • Expecting source line breaks to always become visible line breaks: normal text uses whitespace and wrapping rules.
  • Saying spaces are deleted from the saved file: display handling does not rewrite the original source.
  • Using br to separate unrelated thoughts: use paragraphs where appropriate.
  • Placing hr inside p: keep it as a sibling between the surrounding paragraphs.
  • Adding many empty elements for spacing: use meaningful structure and later CSS.
  • Using pre for every paragraph: preserve spacing only where that spacing is part of the content.
  • Assuming all screens wrap at the same word: available width and text settings vary.

Practice questions

  1. What does p describe?
  2. Predict the ordinary visible text of <p>Try one\nsmall task.</p>, where the source has an actual newline instead of the written backslash-n.
  3. Which element would you use between lines of a short room address?
  4. Why should hr normally sit outside a paragraph?
  5. How does pre differ from normal paragraph text handling?
  6. Create a complete club notice with two paragraphs, a short multiline location and a thematic break before a different enquiry topic. Explain each choice.
Check your practice answers
  1. A paragraph: one connected piece of text.
  2. It normally reads Try one small task. It may still wrap on a narrow display, but not because of that source newline alone.
  3. Br, where the line divisions are meaningful parts of the location text.
  4. P contains paragraph text and suitable text-level content; hr represents a thematic break outside that paragraph content.
  5. Pre normally preserves its spaces and source line breaks. Ordinary paragraph flow usually collapses runs of whitespace and wraps to fit the available width.
  6. Use p for separate thoughts, br for the location's line divisions and hr between topics. Keep the complete document structure and avoid empty elements used only to make gaps.

Interview questions

How do p and br differ?

P describes a paragraph, while br inserts a line break within content without beginning another paragraph. Choose based on the writing, not just the amount of gap you want.

What does hr mean?

It represents a thematic break in the content, often displayed as a horizontal line. A purely decorative border is better handled with CSS.

Why do several typed spaces often appear as one?

Normal browser text styling collapses runs of ordinary whitespace during display. The original source is not rewritten, and other rules such as preformatted text can preserve spacing.

Why avoid repeated br elements for page layout?

They describe line breaks, not a reliable layout spacing system. Excess breaks add meaningless structure and can look different across screens and styles.

Quick revision

  • Use paragraphs to group connected writing.
  • Source newlines, intentional breaks and visual wrapping are different.
  • Br breaks a line within content; hr separates topics.
  • Pre preserves meaningful whitespace.
  • Do not place headings or hr inside p.
  • Use CSS later for layout spacing rather than empty paragraphs or repeated breaks.