Lesson 9 of 36
HTML Tutorial

Rules, Entities and Whitespace

Thematic breaks with hr, special characters with entities, and how browsers collapse whitespace.

3 min readBeginnerWeb FundamentalsHTML Basic Tags

Three small topics round off the basic tags. They look unrelated, but each answers a question every beginner hits sooner or later: how do I divide content, how do I type special characters, and why does my spacing disappear?

The hr element#

<hr> represents a thematic break, a shift of topic between paragraphs. Browsers draw it as a horizontal line.

html
<h2>Breakfast</h2>
<p>Eggs, toast and masala tea served until 11am.</p>
<hr>
<h2>Lunch</h2>
<p>Soup of the day with fresh bread.</p>

Like <br>, it is a void element. It has meaning, not just looks: it says "the topic changes here." If you only want a decorative line, create it with a CSS border instead.

Character entities#

Some characters have special meaning in HTML. The less-than sign starts a tag, so you cannot just type it into your text. Other characters are not on a keyboard at all. For both cases, HTML has entities: codes that begin with an ampersand and end with a semicolon.

html
<p>Fish &amp; chips costs 5 &lt; 6 euros, a &quot;bargain&quot;.</p>
<p>&copy; 2025 Brew and Byte. All rights reserved.</p>
<p>Price: &euro;4 &mdash; or about Rs.&nbsp;600.</p>

The most useful entities:

EntityResultUse
&lt;the less-than signShowing a tag in text
&gt;the greater-than signShowing a tag in text
&amp;the ampersandTyping an ampersand safely
&quot;a double quoteQuotes inside attribute values
&nbsp;a non-breaking spaceKeep two words on one line
&copy;the copyright signFooters

You can also use numeric forms, such as &#169; for the copyright symbol. With UTF-8 encoding (<meta charset="utf-8">) you can often type characters like the rupee symbol directly, but entities remain essential for the reserved characters <, > and &.

To show a code sample containing tags, escape the brackets:

html
<p>To make a paragraph, write <code>&lt;p&gt;Hello&lt;/p&gt;</code>.</p>

How whitespace behaves#

HTML collapses whitespace. Any run of spaces, tabs and line breaks becomes a single space when displayed.

html
<p>Fresh       coffee
   every


   morning.</p>

This shows as "Fresh coffee every morning." on one line. That is a feature: you can format your source neatly without changing the page. To force extra spacing:

  • Use CSS margins and padding for layout.
  • Use <br> for a deliberate line break inside text.
  • Use <pre> when you really need to preserve spaces and line breaks, such as in code or ASCII art.
html
<pre>
Espresso   Rs. 150
Latte      Rs. 220
</pre>

Common mistakes#

  • Typing a raw < in text and watching the content disappear because the browser sees a tag.
  • Forgetting the semicolon at the end of an entity.
  • Using <hr> just as decoration.
  • Pressing Enter several times in source and expecting blank lines.
  • Using &nbsp; for layout.

Try it yourself#

Write a footer line reading: "(c) 2025 Brew and Byte - Tea & Coffee" using the proper copyright entity and an escaped ampersand. Separate two sections of your page with <hr>. Then write a short paragraph with five blank lines and ten spaces in the source, view it in the browser, and explain what happened. Finally wrap a menu in <pre> and compare.

Recap#

hr marks a change of topic. Entities such as &lt;, &gt; and &amp; let you display reserved or special characters. Browsers collapse whitespace, so use CSS for spacing, br for line breaks in text and pre for preformatted text.

Check your understanding

Lesson quiz

Optional

A short quiz to check what you just learned.

Questions
4
Time limit
5 min
Pass mark
70%
Best score
-