Take the 2-minute tour ×

Within an unordered list.

<li><span></span> The lazy dog.</li>
<li><span>AND</span> The lazy cat.</li>
<li><span>OR</span> The active goldfish.</li>

Adding a class or style attribute is permitted but padding the text and adding or changing tags is not allowed.

The page is rendering with Courier New.

Goal is to have text after span lined up.

    The lazy dog.
AND The lazy cat.
OR  The active goldfish.

Justification of the "OR" is unimportant.

The lazy animal text may be wrapped in an additional element but I'll have to double check.

Thanks is advance!

share|improve this question
add comment

8 Answers

up vote 225 down vote accepted
<style type="text/css">
    list-style-type: none;
    padding-left: 0px;

ul li span { 
    float: left;
    width: 40px;

Like Eoin said, you need to put a non-breaking space into your "empty" spans, but you can't assign a width to an inline element, only padding/margin so you'll need to make it float so that you can give it a width.

For a jsfiddle example, see http://jsfiddle.net/laurensrietveld/JZ2Lg/

share|improve this answer
<span> is an inline element by default - and floating it won't give it a width. –  codeinthehole Nov 2 '08 at 23:14
The float property generates a "block box" which does have a width. –  Stephen Caldwell Nov 2 '08 at 23:23
@touqen, the css you've provided doesn't give the span an equal width in ff3 or opera 9.51 –  codeinthehole Nov 3 '08 at 0:00
Should it be diplay: inline-block; width: 32px; will do in most modern browsers. –  Paulo Bueno Jan 9 '12 at 18:18
@Randy Marsh - no, the width property only has an effect because the float property changes the element to a block display, as Stephen Caldwell describes above. –  codeinthehole Mar 9 '12 at 18:44
show 4 more comments

In an ideal world you'd achieve this simply using the following css

<style type="text/css">

span {
  display: inline-block;
  width: 50px;


This works on all browsers apart from FF2 and below.

Firefox 2 and lower don't support this value. You can use -moz-inline-box, but be aware that it's not the same as inline-block, and it may not work as you expect in some situations.

Quote taken from quirksmode

share|improve this answer
this doesnt seem to work on chrome either –  arviman Sep 6 '11 at 18:58
This does work on Chrome. –  Benji XVI Oct 27 '11 at 12:03
this does work on chrome and it's usefull ! –  Charles Feb 15 '12 at 16:48
Sadly, this doesn't work for DomPDF. –  Nicholas Pickering May 2 '13 at 13:53
@NicholasPickering .. how about wkhtmltopdf? –  codeinthehole May 2 '13 at 14:03
show 3 more comments

Unfortunately inline elements (or elements having display:inline) ignore the width property. You should use floating divs instead:

<style type="text/css">
div.f1 { float: left; width: 20px; }
div.f2 { float: left; }
div.f3 { clear: both; }

<div class="f1"></div><div class="f2">The Lazy dog</div><div class="f3"></div>
<div class="f1">AND</div><div class="f2">The Lazy cat</div><div class="f3"></div>
<div class="f1">OR</div><div class="f2">The active goldfish</div><div class="f3"></div>

Now I see you need to use spans and lists, so we need to rewrite this a little bit:

<style type="text/css">
        span.f1 { display: block; float: left; clear: left; width: 60px; }
    li { list-style-type: none; }

<li><span class="f1">&nbsp;</span>The lazy dog.</li>
<li><span class="f1">AND</span> The lazy cat.</li>
<li><span class="f1">OR</span> The active goldfish.</li>
share|improve this answer
That's a great solution. Floating divs mimic the intended behavior of spans as they line up horizontally. It's important to remember the clear:both line break. It's a great way to avoid tables in this context. –  artur Feb 11 '10 at 16:22
add comment

The <span> tag will need to be set to display:block as it is an inline element and will ignore width.


<style type="text/css"> span { width: 50px; display: block; } </style>

and then:

<li>span>AND</span>something else</li>
share|improve this answer
add comment

People span in this case cant be a block element because rest of the text in between li elements will go down. Also using float is very bad idea because you will need to set width for whole li element and this width will need to be the same as width of whole ul element or other container.

Try something like this in html:

<li><span></span><strong>The</strong> lazy dog.</li>
<li><span>AND</span> <strong>The</strong> lazy cat.</li>
<li><span>OR</span>  <strong>The</strong> active goldfish.</li>

and in the css

li {position:relative;padding-left:80px;} // 80px or something else
li span {position:absolute;top:0;left:0;}
li strong {color:red;} // red or else

so, when the li element is relative you format the span element to be as absolute and at the top:0;left:0; so it stays upper left and you set the padding-left (or: padding:0px 0px 0px 80px;) to set this free space for span element.

It should work better for simple cases.

share|improve this answer
add comment

You can do it using a table, but it is not pure CSS.

    text-indent: 40px;

    list-style-type: none;
    padding: 0;

    color: #ff0000;
    position: relative;
    left: -40px;

<span></span><li>The lazy dog.</li>
<span>AND</span><li>The lazy cat.</li>
<span>OR</span><li>The active goldfish.</li>

Note that it doesn't display exactly like you want, because it switches line on each option. However, I hope that this helps you come closer to the answer.

share|improve this answer
add comment

Well, there's always the brute force method:

<li><pre>    The lazy dog.</pre></li>
<li><pre>AND The lazy cat.</pre></li>
<li><pre>OR  The active goldfish.</pre></li>

Or is that what you meant by "padding" the text? That's an ambiguous work in this context.

This sounds kind of like a homework question. I hope you're not trying to get us to do your homework for you?

share|improve this answer
add comment
<style type="text/css">

span {
  width: 50px;


You can do this method for assigning width for inline elements

share|improve this answer
add comment

Your Answer


