CSS Lists

The list properties used to control the presentation of list item markers.

Types of HTML Lists

There are three different types of list in HTML:

  • Unordered lists — A list of items, where every list items are marked with bullets.
  • Ordered lists — A list of items, where each list items are marked with numbers.
  • Definition list — A list of items, with a description of each item.

To know more about lists, please check out the HTML Lists tutorial.


CSS List Properties

The CSS list properties allow you to:

  • Control the shape or appearance of the marker.
  • Specify an image for the marker rather than a bullet point or number.
  • Set the distance between a marker and the text in the list.
  • Specify whether the marker or bullet would appear inside or outside of the box containing the unordered or ordered list items.

These are the following properties which can be used to control lists.

The list-style-type Property

The list-style-type property sets the shape or style of bullet point (also known as amarker) in the case of unordered lists, and the style of numbering characters in ordered lists

The list-style-position Property

The list-style-position property determines whether the marker or bullet point appear inside or outside of the list item’s principal block boxes.

It takes the value inside or outside, with outside being the default. If the value inside is used, the lines will wrap under the marker instead of being indented.

 

The list-style-image Property

The list-style-image property sets an image as the bullet type for a list.

The style rule in the example below assigns a transparent PNG image “arrow.png” as the list marker for all the items in the unordered list.

The example above does not produce the same output in all browsers. Internet Explorer and Opera will display the image-marker slightly higher than Firefox, Chrome, and Safari. See below, for the cross browser solution of this problem.


Cross Browser Solution for Image Marker

When using an image as bullet using the list-style-image property, the bullets does not line up to the text accurately across the browsers. As a work-around, you can properly align bullet images via the background-image CSS property. First, set the list to have no bullets. Then, define a non-repeating background image for the list element.

The following example displays the image-marker equally in all browsers:

The list-style Shorthand property

The list-style property is a shorthand property for defining all the three properties list-style-type, list-style-image, and list-style-position of a list in one place.

This style rule set the list marker for the ordered list items to be uppercase Latin letters that appear inside the list item’s principal block boxes:

Note:When using the shorthand property, the orders of the values are: list-style-type | list-style-position | list-style-image. It doesn’t matter if one of the values above is missing, as long as the rest are in the specified order.

Loading