How do you add a blank line into HTML? Several ways are possible, with each unique approach depending on your specific use case and what is permissible for you to edit with the HTML.
Reasons for why you might need to insert blank lines into your HTML code could be to render it in a PDF. One recent case for myself with a project was having an area at the bottom of a letter where somebody could sign. This might be useful for example when uploading the document to Adobe Sign and having it signed by a couple of parties.
Whatever the reason or use case needed for inserting a blank line into your code, here are several means available for you to use.
I’ve broken up each section according to what is needed to be changed and these are as follows:
- Use HTML tags
- Use HTML entities
- Use CSS
Let’s look at each approach in more detail.
Use HTML Tags
There are three tags which are available to help insert blank lines into your code. These three tags are known as the break tag, pre-formatted tag and paragraph tags.
Let’s look at each in a little more detail.
Using
BR
Tags
If you’re stuck with the parent nodes that wrap your text, then one solution you can use is to
append
a HTML tag to include a blank line by inserting the
<br />
tag.
If a BR tag contains a forward-slash it helps the reader of the code to know the tag is
self-closing
. In other words, it doesn’t need a corresponding closing
</br>
tag.
If you happen to write your
<br>
code without the forward-slash you need not worry about it as most browsers or HTML rendering engines will know the
br
tag is a tag that does not need to have a corresponding closing tag.
Personally, I prefer inserting the forward-slash purely for readability, I can quickly see from the code that the
<br />
tag is self-closing and I don’t need to go hunting around for a missing closing tag.
By inserting the
br
tag at the end of a line, it inserts a “break” (i.e. carriage return) and starts the text after the
<br />
tag on a new line. If an additional blank line is needed, insert another BR tag.
Here’s an example of what the code would look like using
BR
tags and its subsequent result in HTML:
<p>Yours sincerely,<br /><br /><br />Ryan</p>
Yours sincerely,
Ryan
Be careful with using the line break tag into your HTML code. You might want to check my other post on inserting line breaks in HTML about the purpose of a line break.
Using
PRE
Tags
If you can modify the parent node wrapping the area where you want your blank lines to go, then this option may provide the most flexibility without needing to insert any additional tags .
The only issue with using the
<pre>
tags is that you may need to style it to fit with other formats on your page. Also, it will not allow for any other HTML tags to be used inside.
To insert a blank line using the
PRE
tags simply use the enter key on your keyboard and type the information for how it is to appear.
Here is an example using
PRE
tags and its subsequent result in HTML:
<pre>Yours sincerely,
Ryan</pre>
Yours sincerely, Ryan
As you can see from the above example, very
little
is needed in the code to change. However, it does mean the
<pre>
tags will require their specific styling as the renderer or browser will display this quite differently from the rest of your content.
Also, you may have to add a space or two on those blank lines otherwise it may be rendered as a mistake and the blank lines may be removed.
Using
P
Tags
Another way to add a blank line using HTML tags is to use the standard paragraph
<p>
tag.
If structure of your content is important and elements need to be wrapped in paragraph tags you can add a blank line by just inserting an empty paragraph section, like so:
<p>Yours sincerely,</p>
<p></p>
<p>Ryan</p>
Yours sincerely,
Ryan
Now you’ll notice in the above output that WordPress hasn’t rendered the blank paragraph (the
<p></p>
line). Testing whether the above code works is important as some renderers may remove this blank paragraph thinking a mistake has been made.
Therefore, to force the blank line enter something between the paragraph tags something like a space character, or the HTML entity for the non-breaking space
like so:
<p>Yours sincerely,</p>
<p> </p>
<p>Ryan</p>
Yours sincerely,
Ryan
As you can see from the above HTML output, WordPress doesn’t deem the middle paragraph to be an oopsie and therefore renders the middle paragraph, showing an empty blank line.
Using HTML Entity / Character References
Another way of creating a blank line in your HTML output is to use HTML entities. I’ve already demonstrated one HTML entity above with the non-breaking space character
but there are hundreds more.
An HTML entity is a representation of an ASCII character and is annotated by writing them with an ampersand followed by an abbreviation, like
nbsp
, or their ASCII ordinal number (you can read more about this fascinating topic on
ordinal numbers with Python code
here as the same concept applies). Finally, ensure the entity is closed off with a semi-colon.
For example, the non-breaking space character can be written as an abbreviated entity reference like
or as a character reference like
 
with both expressions being equivalent.
Since ISO-8859-1 defined the character set for the HTML 4.01 standard. Within the first 32 characters (from 0 to 31) are the control characters, several of which define a line break.
Using Carriage Return Character Reference
The HTML character reference for the carriage return character is
and an example of this is seen in the following code:
<pre>Yours sincerely, Ryan</pre>
Yours sincerely, Ryan
If nothing was rendered it is likely the operating system isn’t interpreting this as it should. Try the next one…
Using Line Feed Character Reference
Another HTML character available is the Line Feed character, which has the symbol ` ` and this operates in the same way as the carriage return, as seen in the following example:
<pre>Yours sincerely, Ryan</pre>
Yours sincerely, Ryan
This seems to render fine on my mac OS machine, but if you’re using Windows or on a mobile device one or the other may not work. Therefore, it might be best to combine both into something like this:
<pre>Yours sincerely, Ryan</pre>
Yours sincerely, Ryan
I’ve inserted the carriage return character first as some Windows machines prefer this order: carriage return then line feed.
Anyway, try the above HTML character references in your code if this is an option that appeals to you.
Using CSS
All of the above examples require the insertion of additional code, whether that be direct HTML or an ASCII character.
What if there is no ability to insert additional data? Is there a means using CSS to have blank lines?
Using
white-space
CSS Property
One means is to use the
white-space
property in CSS.
There are several options available for this type, but the one I’m most interested in if my text is fixed and I want to output this result according to its output is the option
pre
.
Here is an example demonstrating this use (I’ve inserted the
style
property, but this code could just as easily be inserted into the stylesheet instead):
<p style="white-space:pre">Yours sincerely,
Ryan</p>
Yours sincerely, Ryan
Using margin or padding
If the structure of your code is wrapped in tags for each line, then you might want to look at setting a larger spacing underneath the first line (or a larger spacing above the second line).
A CSS property that can easily allow for this functionality is the
margin-bottom
or
padding-bottom
property.
Here is an example demonstrating the use of
margin-bottom
where each line is wrapped in a HTML tag:
<p style="margin-bottom:2em">Yours sincerely,</p>
<p>Ryan</p>
Yours sincerely,
Ryan
Again this solution best suits when you can’t inject the blank paragraph into the HTML as mentioned above, and each section is wrapped in its own HTML tag.
You may also need to force
!important
on the paragraph which will have the spacing as other CSS properties may override.
Summary
There are several ways to insert a blank line into your HTML code. Some methods depend on what you can inject (if anything at all), whereas other means can use the CSS to help provide the necessary spacing.