Definition and Usage
There are times when you want to control the numbering of ordered lists. For example, your list may be broken up by a paragraph that appears mid-list to expand on a certain concept, or you may create a countdown list that begins at a high number and counts down. Lastly, maybe you'd rather use roman numerals. To reverse the number of a list, simply add the reversed attributed to the opening ol tag.
It should be noted that Microsoft browsers do not support the reversed attribute. If you use this attribute, bear in mind that visitors using Internet Explorer or Edge will see standard numbering. The start attribute is used to to specify the number on which an ordered list starts. For example, imagine you have a list of 5 items, and after the second and fourth items you want to add a sentence or two with additional details. You could use the following HTML to do this without restarting the list numbering after each paragraph.
A few short sentences about Item 2 that we don't want to appear appended to the list item. A second sentence of additional details. We'll use the same technique to properly number Step 5 below.
You can use CSS to change they marker style of an ordered list. In addition to standard numbering referred to as decimal in CSS , you can also use:. We cover the list-style-type CSS property used to implement these numbering styles below.
Description lists are created with the dl tag. Used far less frequently than their ordered and unordered peers, description lists are used to contain name-value groups. Each name-value group consists of one name, or term, placed between dt tags, followed by one or more values with each value, or description, placed between dd tags. For example, if we wanted to use a description list to explain the relationship between members of a family, we might use the following code:.
When that list is rendered, it will be displayed in such a way that the relationships between the terms dt and values dd are clear. A nested list is a list within a list. If you've ever created a bulleted outline in a word processing document you probably used a variety of indentations and bullet point types to denote items that were subpoints of another item in the outline.
This is the effect we're going for when we create nested lists. When that list is loaded in the browser, the nested list will be indented further than the parent list, and a different type of item marker will be displayed. Nested lists aren't just used to organize the visual representation of information. Screen readers and other assistive technologies rely on the nested structure of complex lists to make sense of the hierarchy and logic of data within the list.
You could use assign classes to list items and use CSS to create the same visual effect as a nested list. However, if you did that, the hierarchical and logical structure of the list would be lost to website visitors using assistive technologies. One of the most common uses of lists is to create website navigation menus. The list-style-position property specifies the position of the list-item markers bullet points.
The start of each line of a list item will be aligned vertically. As it is part of the list item, it will be part of the text and push the text at the start:. Note that the list also has default margin and padding. To remove this, add margin: The list-style property is a shorthand property. It is used to set all the list properties in one declaration:. If one of the property values above are missing, the default value for the missing property will be inserted, if any.
Customized list with a red left border This example demonstrates how to create a list with a red left border. Full-width bordered list This example demonstrates how to create a bordered list without bullets.
The type Attribute