Unordered Lists:
|
Ordered Lists:
|
In HTML, there are two primary list types:
CSS list properties enable you to:
The list-style-type property determines the style of the marker used for list items.
Below is an example showcasing a variety of available list item markers:
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; } |
Please note: Certain values correspond to unordered lists, while others are for ordered lists.
The list-style-image property allows you to designate an image as the marker for list items.
Example
ul { list-style-image: url(‘sqpurple.gif’); } |
The list-style-position property determines the placement of list item markers (bullet points).
When set to “list-style-position: outside;”, the bullet points will appear outside the list item, and the start of each line of a list item will be vertically aligned. This is the default behavior.
When specified as “list-style-position: inside;”, the bullet points will be positioned inside the list item. This means they are considered part of the list item’s text, causing the text to be pushed at the beginning accordingly.
Example
ul.a { list-style-position: outside; } ul.b { list-style-position: inside; } |
The list-style-type: none property is utilized to eliminate markers or bullets from lists. It’s important to note that lists also have default margin and padding. To remove these defaults, apply margin:0 and padding:0 to <ul> or <ol>.
Example
ul { list-style-type: none; margin: 0; padding: 0; } |
The list-style property serves as a shorthand for setting all list properties in a single declaration.
Example
ul { list-style: square inside url(“sqpurple.gif”); } |
When employing the shorthand property, the order of property values is as follows:
If any of the above property values are omitted, the default value for the missing property will be applied, if available.
You can enhance the appearance of lists by applying colors, adding visual interest to them.
Styles applied to the <ol> or <ul> tag will affect the entire list, while properties added to the <li> tag will impact individual list items.
Example
ol { |
Result:
Property |
Description |
list-style |
Combines all list properties into a single declaration. |
list-style-image |
Uses an image as the list-item marker. |
list-style-position |
Defines the position of list-item markers (bullet points). |
list-style-type |
Defines the type of list-item marker. |