Different ways to add Breaks and Spaces in HTML.
In HTML, Breaks and Spaces can be added using various elements and entities. The <br> tag creates a line break, while 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
- Entity: The entity represents a non-breaking space, preventing the browser from collapsing consecutive spaces.
First 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>