Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

CSS Lists

CSS Lists


CSS list properties are used as follows:


List

In HTML, there are two types of lists:

With CSS, lists can be styled further, and images can be used as list item markers.

An unordered list looks like this:

An ordered list looks like this:

  1. Coffee

  2. Tea

  3. Coca Cola

  4. Coffee

  5. Tea

  6. Coca Cola


Different list item markers

The list-style-type property specifies the type of list item marker:

Example

ul

.a

{

list-style-type:

circle

;

}

ul

.b

{

list-style-type:

square

;

}

ol

.c

{

list-style-type:

upper-roman

;

}

ol

.d

{

list-style-type:

lower-alpha

;

}

Try it »

Some values are for unordered lists, and some are for ordered lists.


Images as list item markers

To specify an image as the list item marker, use the list-style-image property:

Example

ul

{

list-style-image:

url

('

sqpurple

.

gif

')

;

}

Try it »

The above example does not display the same in all browsers; IE and Opera display the image marker slightly higher than Firefox, Chrome, and Safari.

If you want the same image marker in all browsers, you should use a browser compatibility solution, as follows

Browser compatibility solution

To display the image marker the same in all browsers, the following example:

Example

ul

{

list-style-type:

none

;

padding:

0

px

;

margin:

0

px

;

}

ul

li

{

background-image:

url

(

sqpurple

.

gif

)

;

background-repeat:

no-repeat

;

background-position:

0

px

5

px

;

padding-left:

14

px

;

}

Try it »

Example explanation:

- Set the list type to no list item marker - Set padding and margin to 0px (browser compatibility) - Set the URL of the image and make it display only once (no repetition) - Position the image (left 0px, top and bottom 5px) - Use the padding-left property to place the text in the list

List - shorthand property

All list properties can be specified in a single property. This is called a shorthand property.

When using the shorthand property for lists, the list style properties are set as follows:

Example

ul

{

list-style:

square

url

("

sqpurple

.

gif

")

;

}

Try it »

The following properties can be set in order:

If one of the above values is missing, the rest still follow the specified order, and that is fine.


More examples

All the different list item markers
This example demonstrates all the different CSS list item markers.


Remove the default settings

The list-style-type:none property can be used to remove the small markers. By default, lists