Home : Internet : CSS : List

How To Format Bullet Lists (<ul>) Using CSS

MediaCollege.com YouTube Channel

Bullet lists in HTML come in two varieties: Ordered Lists (in which each line begins with a number or letter) and Unordered Lists (in which each line begins with the same bullet shape or image).

Ordered list   Unordered List   Unordered List with CSS Style
  1. Line 1
  2. Line 2
  3. Line 3
   
  • Line 1
  • Line 2
  • Line 3
   
  • Line 1
  • Line 2
  • Line 3

On this page we will discuss how to format unordered lists so they have a bit more style. We'll also show you how to use an image for bullet lists.


CSS Styles

There are several ways to format the style of your lists but they all use the same basic set of instructions. These are CSS (Cascading Style Sheet) instructions and they look like this:

font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
line-height: 2em;

These are just a small sample of the styles which are available. The ones above are common CSS styles and can be used anywhere there is text. There are also styles specific to lists, such as:

list-style-position: outside;
list-style-image: url(arrow.gif);
list-style-type: square;

When formatting a list, you can choose as many of these styles as you like. If you only need to use an image for the bullets, then that's the only style you choose. For this page we will use the following requirements to illustrate the methods:

More formatting options will follow later.


Method 1: Universal Style

The simplest way to format your lists is to define a style which applies to all lists in the page. In the head of your web page, add the following code:

<style type="text/css">
ul { list-style-image: url("/images/arrow.gif") }
</style>

Syntax: list-style-type: <value>
Possible Values: disc | circle | square | decimal | lower-roman | upper-roman | lower-alpha | upper-alpha | none

Default Value: disc
Applies to: Elements with display value list-item
Inherited: Yes
Specifies the type of list-item marker, and is used if list-style-image is none or if image loading is turned off

Syntax: list-style-image: <value>
Possible Values: <url> | none

Default Value: one
Applies to: Elements with display value list-item
Inherited: Yes
Replaces the marker specified in the list-style-type property.

Syntax: list-style-position: <value>
Possible Values: inside | outside
Default Value: outside
Applies to: Elements with display value list-item
Inherited: Yes
Takes the value inside or outside, with outside being the default. This property determines where the marker is placed in regard to the list item. If the value inside is used, the lines will wrap under the marker instead of being indented.


Example

  • Line 1
    Second Line
  • Line 2
  • Line 3

The example on the right is the result of the style below. Note that both a list-style-type and list-style-type are defined - the arrow image is used unless it cannot be found or the user has image display disabled, in which case the list uses square bullets.

<style type="text/css">
ul {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: 2em;
font-weight: normal;
font-variant: normal;
text-transform: none;
color: #00CC33;
text-decoration: none;
background-color: #CCCCCC;
text-indent: 5px;
list-style-position: outside;
list-style-image: url(arrow.gif);
list-style-type: square;
padding: 6px;
margin: 2px;
}
</style>

Subscribe to us on YouTube