Open In App

Different ways to add Breaks and Spaces in HTML.

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In HTML, Breaks and Spaces can be added using various elements and entities. The <br> tag creates a line break, while &nbsp; represents a non-breaking space. Additionally, the <p> tag defines a paragraph, creating space between blocks of text.

CSS properties like margin and padding can also be used for more precise control over spacing within HTML elements, offering flexibility in design and layout.

Line Breaks

  • <br> Tag: The <br> tag is used to insert a line break within the text.
First line<br>Second line
  • <p> Tag: The <p> tag represents a paragraph and automatically adds space above and below the enclosed text.
<p>Paragraph 1</p>
<p>Paragraph 2</p>

Horizontal Spaces

  • &nbsp; Entity: The &nbsp; entity represents a non-breaking space, preventing the browser from collapsing consecutive spaces.
First&nbsp;Second
  • <pre> Tag: The <pre> tag defines preformatted text and preserves both spaces and line breaks.
<pre>
Preformatted
Text with Spaces
</pre>
  • CSS white-space Property:
<style>
.preserve-space {
white-space: pre;
}
</style>

<div class="preserve-space">Preserve Spaces</div>

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads