Take the 2-minute tour ×

I'm trying to justify the text within this p tag so that it perfectly fits the width of the p.

<p align="justify" style="text-align: justify !important; color:#fff; margin:0px; font-weight:bold; width:487px; border:Solid 1px red;">blah blah blah</p>

but the text just wont justify! any idea why?

thanks for any help.

share|improve this question

5 Answers 5

You can use the solution described here: http://blog.vjeux.com/2011/css/css-one-line-justify.html

This will justify a single line but adds a space after, so if you know the height, you can specify it with overflow:hidden to conceal it and still get the justification.

<!-- HTML -->
<p id="tagline" class="fulljustify">Blah blah blah</p>

/* CSS */
.fulljustify {
.fulljustify:after {
    content: "";
    display: inline-block;
    width: 100%;    
#tagline {
    height: 80px;
    overflow: hidden;
    line-height: 80px; /* vert-center */
share|improve this answer
Thanks worked for me. :) –  Bibhu Feb 16 '12 at 11:04
For a single line, this –  Scott Grodberg Jun 16 at 19:17

If your text doesn't span more than one line, justifying doesn't do anything. Your text has to wrap to the next line, and then the FIRST line will be justified, but not the second.

share|improve this answer
darn. so theres no css way to justify 4 words in a 487 width p? –  phil Jun 3 '11 at 14:31
@phil - not that I know of... –  Brett Jun 3 '11 at 14:32
is correct. You also needed to change the color from white on a white background to see this. jsfiddle.net/5RpQr –  Jason Gennaro Jun 3 '11 at 14:34
@jason gennaro - yeah, i spent a minute trying to figure out why i didn't see anything in the fiddle... haha –  Brett Jun 3 '11 at 14:35
.haha @phil, see my answer for a possible other solution re justifying four words –  Jason Gennaro Jun 3 '11 at 14:40

If you wanted to justify four words in 487px you could try using word-spacing in your css.

I used word-spacing:8em; for bla bla bla bla but you could adjust as necessary.


share|improve this answer
@phil - Just remember that if you change your words, the word spacing must change too –  Brett Jun 3 '11 at 14:42
@Brett exactly. –  Jason Gennaro Jun 3 '11 at 14:43

Just use style="text-align:justify".
It works in all browsers.

share|improve this answer
some kind of explanation would be helpful, won't it? he obiviously used your styles... –  Ron Jan 26 '13 at 9:29
@Ron If you want to justify whole paragraph except last row use above trick, and if you want to justify last line also then use ` .justify:after{content: ""; display: inline-block; width: 100%;}` and no need to define height. –  S.K. Dhanda Feb 1 '13 at 16:03
Nope, does not work. –  Siddharth Mar 23 '13 at 16:07

Chrome doesn't support it but in Firefox and IE, you can use text-align-last: justify;. For a cross-browser solution, we have to use what @onemanarmy posted ;)

share|improve this answer

Your Answer


