Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show white space at the beginning of a text in HTML

How do I display white space at the beginning of text in HTML?

For example, I want to use

<p>             This is a paragraph.</p> //             This is a paragraph. 

But it behaves exactly like

<p>This is a paragraph.</p>

How I can do this?

like image 282
user6468132 Avatar asked Jun 27 '16 10:06

user6468132


People also ask

How do I show white space in HTML?

Since there is no blank space keyboard character in HTML, you must type the entity &nbsp; for each space to add. To insert blank spaces in text in HTML, type &nbsp; for each space to add. For example, to create five blank spaces between two words, type the &nbsp; entity five times between the words.

How do you put a space on top of text in HTML?

Creating extra spaces before or after text To create extra spaces before, after, or in-between your text, use the &nbsp; (non-breaking space) extended HTML character.

How do you code white space?

White space is created by pressing the Return key [\n|\r|\r\n], Spacebar key [ ], or the Tab key [\t]. White space is essentially any bit of space in your code that is not taken up by „physical“ characters.

What is white space Nowrap in HTML?

nowrap. Sequences of whitespace will collapse into a single whitespace. Text will never wrap to the next line. The text continues on the same line until a <br> tag is encountered.


2 Answers

You can use white-space: pre; property in CSS which doesn't collapse spaces:

    p {
    	white-space: pre;
    	color: black;
    	background: pink;
    }
    <p>             This is a paragraph.</p>
like image 71
Rokin Avatar answered Oct 14 '22 19:10

Rokin


If you have to have spaces you can use &nbsp;, so code would look like:

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

For 5 spaces. Though I think you may be best using css to add padding / margin styling to achieve what you are after.

EDIT

Snippet added using padding method:

p.padded {
  padding:.3em .5em .1em 2em;
}
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum voluptas, culpa, quam, totam ex illum earum cupiditate, odit delectus cum atque dignissimos. Culpa praesentium perspiciatis incidunt pariatur. Doloremque, illum, sequi.</p>

<p class="padded">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rerum voluptas, culpa, quam, totam ex illum earum cupiditate, odit delectus cum atque dignissimos. Culpa praesentium perspiciatis incidunt pariatur. Doloremque, illum, sequi.</p>
like image 35
Mike Harrison Avatar answered Oct 14 '22 18:10

Mike Harrison