Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I keep HTML from removing whitespaces?

    <p>This    is    a    paragraph</p>

becomes

This is a paragraph

but I want it to remain as is. Like

This is a paragraph

How do I do it?

like image 353
user3676357 Avatar asked Oct 19 '25 17:10

user3676357


2 Answers

If you don't want to use &nbsp;, you can use something like

<p class="allspace">This is a paragraph</p>

.allspace { white-space: pre }

white-space:pre will format the html with spaces. This approach is better as it doesn't require multiple use of &nbsp;

like image 94
Mohd Asim Suhail Avatar answered Oct 22 '25 09:10

Mohd Asim Suhail


Use &nbsp; - it is a non-breakable space.

For example:

<p>This&nbsp;&nbsp;&nbsp;&nbsp;is&nbsp;&nbsp;&nbsp;&nbsp;a&nbsp;&nbsp;&nbsp;&nbsp;paragraph</p>

A non-breaking space (also called no-break space, non-breakable space (NBSP), hard space, or fixed space) is a space character that prevents an automatic line break at its position. In some formats, including HTML, it also prevents consecutive whitespace characters from collapsing into a single space.

like image 38
u32i64 Avatar answered Oct 22 '25 09:10

u32i64



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!