HTML Codes for Whitespace and Line Breaks

Accurate, factual information from observations
Post Reply
shukla7789
Posts: 1259
Joined: Tue Dec 24, 2024 4:29 am

HTML Codes for Whitespace and Line Breaks

Post by shukla7789 »

For most people, formatting text is one of the most boring tasks when publishing a post. Luckily, text editors that integrate CMS like WordPress make things much easier and the average user doesn't need to know anything about HTML to run their blog. Even so, it's always good to know some HTML, for the same reason that it's good to learn how to multiply even if you always use a calculator: you never know when you're going to need it. On this occasion, I want to teach you the HTML whitespace and line break codes.

I don't know about you, but I've had the experience of lawyer database the WordPress editor not respect the spaces I left between paragraphs and having to insert them manually into the code. So I can say that these codes have saved my life on occasion.

How to put whitespace and line breaks in HTML
Types of whitespace in HTML
In HTML language, these four cases are considered white spaces:

Spaces between words
Tabulator
Carriage return
Line break
By default, HTML ignores “extra” whitespace, which in this case is all whitespace that is not the space that separates words. To help you understand, here is an example. If you write the following text in HTML:

Hello,

my name is

William Penguin

When published on a website it will look like this:

Hello, my name is William Penguin

Do you see it? It appears all together because HTML does not recognize those line breaks. To make it do so, you need to use one of the tags I present below:

<br> tag for HTML line breaks
The <br> tag is an empty tag, meaning that you don't need to put an opening and closing tag. The equivalent of this tag is pressing Enter while typing, which inserts a line break.
Post Reply