CSS lists are one of the most versatile elements of web design. Aside from being used for making, well, lists, they are also used for navigation, layouts, slideshows, carousels, and so on.
Let's see some of their properties.
The list-style
CSS property is shorthand for the list-style-type
, list-style-image
, and list-style-position
properties. These properties are actually the values that the list-style
CSS property supports. We'll see all these properties next.
The list-style
property supports one, two, or three values, in any order. If a value isn't declared, it will use its default value.
CSS:
/*Default values*/ ul { list-style: disc outside none; } /*One value, the other two are default*/ ul { list-style: circle; } /*Two values, the other one is defaults*/ ul { list-style: lower-roman inside; } /*Three values*/ ul { list-style: decimal outside url(../images/list-bullet.png); }
The
list-style-type
CSS property defines the type of graphic or marker (also called bullet) the list will use. The color of the marker is determined by the color of the text of the element it's applied to.
The list-style-type
property supports many values, but we'll list 15 of the most commonly used ones: armenian
, circle
, decimal
, decimal-leading-zero
, disc
, georgian
, lower-alpha
, lower-greek
, lower-latin
, lower-roman
, none
, square
, upper-alpha
, upper-latin
, and upper-roman
.
Here's a screenshot with all values except the none
value:
CSS:
/*Style: 01, 02, 03...*/ ul { list-style-type: decimal-leading-zero; } /*Style: α, β, γ...*/ ul { list-style-type: lower-greek; } /*Style: A, B, C...*/ ul { list-style-type: upper-latin; }
The
list-style-position
CSS property defines the location of the marker.
The list-style-position
property supports two keyword values: inside
and outside
.
When the inside
value is applied, the marker will appear inside the text. If there's a line that wraps, the marker will be flushed to the left and not "sticking out" like in traditional lists.
The
list-style-image
CSS property allows us to replace the default markers with a custom image.
The list-style-image
property supports one keyword value and one function: none
and url()
.
none
: No image is used to replace the markerurl()
: It's used to define the path to the image that will replace the markerCSS:
ul { list-style-image: url(../images/list-bullet.png); }
Here's a demo in CodePen with all HTML lists: http://tiny.cc/html-lists
13.58.121.8