Skip to main content

CSS Styling Lists

In HTML there are two main types of lists:

  • <ul> — unordered lists, where items are marked with bullets.
  • <ol> — ordered lists, where items are marked with numbers or letters.

CSS has these properties for styling lists:

  • list-style-type — sets the type of marker.
  • list-style-image — uses an image as the marker.
  • list-style-position — sets the position of the markers.
  • list-style — a shorthand for the properties above.

CSS Style List-item Markers

The list-style-type property sets the type of marker for a list.

Note: Some values are for unordered lists and some for ordered lists.

Example

Several marker types are shown: circle, disc, square, upper-roman, lower-roman, lower-alpha, and decimal.

Prompt
An HTML page that shows different list-style-type markers. In an internal <style> block, make unordered list classes a, b, c with circle, disc, square; and ordered list classes d, e, f, g with upper-roman, lower-roman, lower-alpha, decimal. Add a list of each class with a few items.
Output: complete HTML page

CSS Replace List-item Marker with an Image

The list-style-image property replaces the marker with an image.

Note: Also set a list-style-type as a fallback in case the image is unavailable.

Example

The markers are replaced with an image, with square as the fallback.

Prompt
An HTML page that replaces the list marker with an image. In an internal <style> block, set a <ul> list-style-image to url('sqpurple.gif') and also list-style-type square as a fallback. Add a list with a few items.
Output: complete HTML page

CSS Position the List-item Markers

The list-style-position property sets where the markers sit.

outside (the default) puts the markers outside the list item, so the text of each item lines up vertically. inside puts the markers inside the list item, so they become part of the text and push it along.

Example

One list uses outside markers and the other uses inside markers.

Prompt
An HTML page that shows the list-style-position property. In an internal <style> block, make one <ul> class with list-style-position outside (the default) and one with inside. Give each list a border so the difference in where the markers sit is clear. Add a list of each class.
Output: complete HTML page

CSS Remove List-Item Markers

Set list-style-type: none to remove the markers.

Note: A list has default margin and padding. To remove them, add margin: 0 and padding: 0 to the <ul> or <ol>.

Example

The markers and default spacing are removed from the list.

Prompt
An HTML page that removes the list markers and default spacing. In an internal <style> block, set a <ul> list-style-type to none, margin to 0, and padding to 0. Add a list with a few items.
Output: complete HTML page

CSS list-style Shorthand Property

The list-style property is a shorthand for setting all the list properties in one declaration.

The order of the values is: list-style-type, list-style-position, list-style-image. If a value is missing, its default is used.

Example

One shorthand sets the marker type, position, and image together.

Prompt
An HTML page that uses the list-style shorthand property. In an internal <style> block, set a <ul> list-style to "square inside url('sqpurple.gif')" (type, position, image in that order). Add a list with a few items.
Output: complete HTML page

CSS Styling List With Colors

You can also style lists with colors, margins, and padding to make them more interesting.

Anything added to the <ol> or <ul> affects the whole list, while properties on the <li> affect the individual items.

Example

The lists and their items are given different background colors, padding, and margins.

Prompt
An HTML page that styles lists with colors, margins, and padding. In an internal <style> block, give <ol> a salmon background and padding, and <ol> <li> a mistyrose background, darkred text, padding, and left margin. Give <ul> a powderblue background and padding, and <ul> <li> a mistyrose background, darkblue text, and margin. Add an ordered list and an unordered list.
Output: complete HTML page

All CSS List Properties

A summary of the list properties:

  • list-style — sets all the list properties in one declaration.
  • list-style-image — uses an image as the marker.
  • list-style-position — sets the position of the markers.
  • list-style-type — sets the type of marker.