List basics

edit

There are three types of lists: ordered lists, unordered lists, and definition lists. In the following sections, various list types are used for different examples, but other list types will generally give corresponding results.

wikitext rendering
* Lists are easy to do:
** start every line
* with a star
** more stars mean
*** deeper levels
  • Lists are easy to do:
    • start every line
  • with a star
    • more stars mean
      • deeper levels
*A newline
*in a list  
marks the end of the list. Of course
*you can
*start again.
  • A newline
  • in a list

marks the end of the list. Of course

  • you can
  • start again.
# Numbered lists are good
## very organized
## easy to follow
  1. Numbered lists are good
    1. very organized
    2. easy to follow
Definition lists:
; Term : Definition
or
; Term
: Definition
Can be used for more than terms and definitions.

Definition lists:

Term
Definition

or

Term
Definition

Can be used for more than terms and definitions.

* Or create mixed lists
*# and nest them
*#* like this.
*#*; Fruits
*#*: Apple
*#*: Blueberry
  • Or create mixed lists
    1. and nest them
      • like this.
        Fruits
        Apple
        Blueberry
# A line-break in an item is done with HTML<br />like this.
# Just breaking the line will accidentally end the list
like this.
# This was supposed to be item 3, not a new list.
  1. A line-break in an item is done with HTML
    like this.
  2. Just breaking the line will accidentally end the list

like this.

  1. This was supposed to be item 3, not a new list.
* A new paragraph in an item is also HTML.<p>Like so.</p>
* Same goes for<blockquote>"block quotations"</blockquote>like that.
* Note that these are done without line-breaking the wikicode.
  • A new paragraph in an item is also HTML.

    Like so.

  • Same for

    "block quotations"

    like that.
  • Note that these are done without line-breaking the wikicode.


Paragraphs and other breaks

edit

All of the techniques described in this section can be used with each other and with any type of list, at any list level.

Paragraphs inside list items

edit

For simplicity, list items in pure wiki markup cannot be more complex than a basic paragraph. A line break in the wikicode of a list item will end not just the item but the entire list, and reset the counter on ordered lists. Separating unordered list items with blank lines may look approximately normal on-screen, but it creates many separate one-item lists, which is a problem for people using screen readers and is prohibited by the policy on accessibility for people with disabilities, and is also problematic for machine analysis of the article, and for reuse of Wikipedia content more generally.

Paragraphs can be created inside list items by using the HTML ‎<p>...‎</p> (paragraph) element around the second and subsequent paragraphs, with no line-breaks in the wiki code:

#Paragraph 1.<p>Paragraph 2.</p><p>Paragraph 3.</p>
#Second item.

gives

  1. Paragraph 1.

    Paragraph 2.

    Paragraph 3.

  2. Second item

Do not use <br /><br /> as a substitute for ‎<p>...‎</p>; they have different semantic meanings and are not interchangeable.

For code readability (the improvement is more apparent when the paragraphs are long, rather than with short examples like these), line-breaks may be created with HTML comments, <!-- ... -->, that begin on one line against the end of that line's code and end on another line, against the beginning of that line's code:

#Paragraph 1.<!--
 --><p>Paragraph 2.</p><!--
 --><p>Paragraph 3.</p>
#Second item.
  1. Paragraph 1.

    Paragraph 2.

    Paragraph 3.

  2. Second item.

This technique can be used with the other examples below.

Line breaks inside list items

edit

Use a single <br /> for a non-paragraph line break, e.g. where using a nested list is not desired because sub-items are already preceded by numbers:

Recipe:

#Gather ingredients:<br />1{{frac|1|2}} tsp eye of newt (powdered)<br />2 bat wings<br />4 cups mandrake root juice
#Stir in cauldron over low flame for 30 minutes

gives

  1. Gather ingredients:
    112 tsp eye of newt (powdered)
    2 bat wings
    4 cups mandrake root juice
  2. Stir in cauldron over low flame for 30 minutes

Nested blocks inside list items

edit

Similar HTML usage can provide for block quotations within list items:

*Beginning of first item.<blockquote>A large quotation.</blockquote>Rest of first item.<br /><br />
*Second item.

or

*Beginning of first item.<!--
 --><blockquote>A large quotation.</blockquote><!--
 -->Rest of first item.<br /><br />
*Second item.

gives

  • Beginning of first item.

    A large quotation.

    Rest of first item.

  • Second item.


Another case like this is small nested code blocks:

The {{tnull|fnord}} template has two parameters:
#{{para|foo}} This indicates the ''foo'' level:<br /><pre>{{fnord|foo=20}}</pre>
#{{para|bar}} This indicates...

gives

The {{fnord}} template has two parameters:

  1. |foo= This indicates the foo level:
    {{fnord|foo=20}}
  2. |bar= This indicates...

Here, wiki code linebreaks still cannot occur inside the list item, even if they are inside ‎<pre>...‎</pre>, and the HTML comment trick does not work with ‎<pre>, which is why this technique is only suitable for short code examples.

Continuing a list item after a sub-item

edit

In HTML, a list item may contain several sublists, not necessarily adjacent; thus there may be parts of the list item not only before the first sublist, but also between sublists, and after the last one.

In wikicode, unfortunately, sublists follow the same rules as sections of a page: the only possible part of the list item not in sublists is before the first sublist.

In the case of an unnumbered first-level list in wikicode, this limitation can be somewhat worked around by splitting the list into multiple lists; indented text between the partial lists may visually serve as part of a list item after a sublist. However, many readers find this confusing, as the indentation makes it look more like a continuation of the last sublist item. Also, this technique may give, depending on CSS, a blank line before and after each list, in which case, for uniformity, every first-level list item could be made a separate list, with further complicates the code. For complex lists like this, it is recommended to use the HTML technique, and to replace instances of the "quick and dirty" wikicode version with the HTML version.

Numbered lists illustrate that what should look like one list may, for the software, consist of multiple, nested lists. Unnumbered lists give a corresponding result, except that the problem of restarting with 1 is not applicable.

<ol>
  <li>list item A1
    <ol>
      <li>list item B1</li>
      <li>list item B2</li>
    </ol>continuing list item A1
  </li>
  <li>list item A2</li>
</ol>
  1. list item A1
    1. list item B1
    2. list item B2
    continuing list item A1
  2. list item A2
vs.
#list item A1
##list item B1
##list item B2
#:continuing list item A1
#list item A2
  1. list item A1
    1. list item B1
    2. list item B2
    continuing list item A1
  2. list item A2

One level deeper, with a sublist item continuing after a sub-sublist, one gets even more blank lines; however, the continuation of the first-level list is not affected:

#list item A1
##list item B1
###list item C1
##:continuing list item B1
##list item B2
#list item A2

gives

  1. list item A1
    1. list item B1
      1. list item C1
      continuing list item B1
    2. list item B2
  2. list item A2

See also m:Template:List demo (backlinks, edit) and subdivisions.

Spacing between items

edit

For an unordered list with items that are more than one paragraph long, using the HTML comment trick mentioned above to add a blank line between items in the wikicode may be necessary to avoid editor confusion. This is done with a commented-out line:

#First item<!--
                                                -->
#Second item

This doesn't produce unwanted visible spacing or bad list code in the rendered page like adding a plain blank line would:

  1. First item
  2. Second item

The comment must begin on the same line on which the preceding item ends, and the comment must end on its own line. Wrong:

#First item
<!--
                                                -->
#Second item

Wrong:

#First item
<!--
                                                
-->#Second item

If the rendered text has a readability problem due to complex list items, or for some other reason space is desired between list items, simply add a pair of explicit HTML line-breaks to the end of the list items:

#Item 1<br /><br />
#Item 2<br /><br />

gives

  1. Item 1

  2. Item 2

Compare the version without the spacing:

  1. Item 1
  2. Item 2

Changing the list type

edit

The list type (which type of marker appears before the list item) can be changed in CSS by setting the list-style-type property:

wikitext rendering
<ol style="list-style-type: lower-roman;">
  <li>About the author</li>
  <li>Foreword to the first edition</li>
  <li>Foreword to the second edition</li>
</ol>
  1. About the author
  2. Foreword to the first edition
  3. Foreword to the second edition

Extra indentation of lists

edit

In a numbered list in a large font, some browsers do not show more than two digits, unless extra indentation is applied (if there are multiple columns: for each column). This is fixed by increasing the default indentation of 3.2em by 2em more, and it can be done in multiple ways:

wikitext rendering comments
<ol style="margin-left: 5.2em;">
  <li>abc</li>
  <li>def</li>
  <li>ghi</li>
</ol>

  1. abc
  2. def
  3. ghi

When using explicit HTML ‎<li> list items, use an explicit CSS margin spacing of 4em to double the default 2em spacing. Though not the simplest, this is the cleanest and most versatile method, as it does not rely on any peculiarities of the parser, nor on abusing any semantic markup for purely visual purposes. It allows starting with a number other than 1 (see below). It is the recommended method for complex lists.

<ol>
  <ol>
    <li>abc</li>
    <li>def</li>
    <li>ghi</li>
  </ol>
</ol>

    1. abc
    2. def
    3. ghi
The parser translates an ordered list, ‎<ol>, without any list items, ‎<li> (in this case, it contains just another ‎<ol>) into a ‎<div> with a style="margin-left: 2em;", causing indentation of the contents. This is a common, versatile but potentially confusing method, as it allows starting with a number other than 1 (see below). It is klugey, unnecessarily complex and may be confusing to other editors, because it looks like invalid HTML. The parser corrects it on-the-fly, but only MediaWiki experts know this, with the result that other editors may try to "correct" it by removing what looks like redundant ‎<ol> code.
<ol>
#abc
#def
#ghi
</ol>

    1. abc
    2. def
    3. ghi

Just put an explicit HTML ‎<ol>...‎</ol> around wiki-markup list items. It functions the same as the previous example with the content of the "ordered list without any list items", which itself is an ordered list, expressed with # codes; the HTML produced, and hence the rendering, is the same. This is the simplest method, and recommended when starting a simple list with number 1.

:#abc
:#def
:#ghi
 
  1. abc
  2. def
  3. ghi
A list of one or more lines starting with a colon creates a definition list without definition terms, and with the items as definition descriptions, hence indented. However, if the colons are in front of the codes "*" or "#" of an unordered or ordered list, the list is treated as one definition description, so the whole list is indented. Deprecated method: This technique produces poorly formed (though technically DTD-validating) markup and abuses the semantic HTML purpose of definition lists for a purely visual effect, and is thus a usability and accessibility problem. It will work in a hurry, but should be replaced with cleaner code, using one of the techniques described above.

The page meta:Help:List demo demonstrates that several of these methods show all digits of 3-digit numbers.

Specifying a starting value

edit

Specifying a starting value is only possible with HTML syntax. (W3C has deprecated the start and value attributes as used below in HTML 4.01 and XHTML 1.0. But as of 2007, no popular web browsers implement CSS counters, which were to replace these attributes. Wikimedia projects use XHTML Transitional, which contains the deprecated attributes.)

<ol start="9">
<li>Amsterdam</li>
<li>Rotterdam</li>
<li>The Hague</li>
</ol>

gives

  1. Amsterdam
  2. Rotterdam
  3. The Hague

Or:

<ol>
<li value="9">Amsterdam</li>
<li value="8">Rotterdam</li>
<li value="7">The Hague</li>
</ol>

gives

  1. Amsterdam
  2. Rotterdam
  3. The Hague

Only the list item whose value is being set needs to be written in HTML, the rest of the list may use Wiki syntax:

#<li value="9">Amsterdam</li>
#Rotterdam
#The Hague

gives

  1. Amsterdam
  2. Rotterdam
  3. The Hague

This does not work inside <ol>...</ol>.

Comparison with a table

edit

Apart from providing automatic numbering, the numbered list also aligns the contents of the items, comparable with using table syntax:

{|
|-
| align=right |  9.||Amsterdam
|-
| align=right | 10.||Rotterdam
|-
| align=right | 11.||The Hague
|}

gives

9. Amsterdam
10. Rotterdam
11. The Hague

This non-automatic numbering has the advantage that if a text refers to the numbers, insertion or deletion of an item does not disturb the correspondence.

Multi-column bulleted list

edit
{| 
| 
*1
*2 
| 
*3
*4
|}

gives:

  • 1
  • 2
  • 3
  • 4

Multi-column numbered list

edit

Specifying a starting value is useful for a numbered list with multiple columns, to avoid restarting from one in each column. As mentioned above, this is only possible with HTML-syntax (for the first column either wiki-syntax or HTML-syntax can be used).

In combination with the extra indentation explained in the previous section:

{| valign="top"
|-
|<ul><ol start="125"><li>a<li>bb<li>ccc</ol></ul>
|<ul><ol start="128"><li>ddd<li>ee<li>f</ol></ul>
|}

gives

    1. a
    2. bb
    3. ccc
      1. ddd
      2. ee
      3. f

      Using {{multi-column numbered list}} the computation of the starting values can be automated, and only the first starting value and the number of items in each column except the last has to be specified. Adding an item to, or removing an item from a column requires adjusting only one number, the number of items in that column, instead of changing the starting numbers for all subsequent columns.

      {{Multi-column numbered list|125|a<li>bb<li>ccc|3|<li>ddd<li>ee<li>f}}

      gives

        1. a
        2. bb
        3. ccc
          1. ddd
          2. ee
          3. f
          {{Multi-column numbered list|lst=lower-alpha|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}

          gives

            1. a
            2. bb
            3. ccc
              1. ddd
              2. ee
                1. f
                {{Multi-column numbered list|lst=lower-roman|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}

                gives

                  1. a
                  2. bb
                  3. ccc
                    1. ddd
                    2. ee
                      1. f
                      {{Multi-column numbered list|lst=disc|125|a<li>bb<li>ccc|3|<li>ddd<li>ee|2|<li>f}}

                      gives

                        1. a
                        2. bb
                        3. ccc
                          1. ddd
                          2. ee
                            1. f

                            Note that the starting values of each column (125, +3, +2) have no effect when the disc list type is used.

                            Streamlined style or horizontal style

                            edit

                            It is also possible to present short lists using very basic formatting, such as:

                            ''Title of list:'' example 1, example 2, example 3
                            

                            Title of list: example 1, example 2, example 3

                            This style requires less space on the page, and is preferred if there are only a few entries in the list, it can be read easily, and a direct edit point is not required. The list items should start with a lowercase letter unless they are proper nouns.

                            Tables

                            edit

                            A one-column table is very similar to a list, but it allows sorting. If the wikitext itself is already sorted with the same sortkey, this advantage does not apply. A multiple-column table allows sorting on any column.

                            See also Help:Table.

                            Manipulating lists with user stylesheets

                            edit

                            Template:Rellink Virtual anything about how lists are displayed can be customized at the user end with CSS. Some of the more useful tweaks are outline below.

                            Extra indentation

                            edit

                            As noted above, in a numbered list in a large font, some browsers do not show more than two digits, unless extra indentation is applied (if there are multiple columns: for each column). While this should be fixed in the wikicode, user stylesheet CSS can work around the problem for as long as it is present, by increasing the default indentation of 3.2em by 2em more:

                            ol { margin-left: 5.2em;}
                            

                            Changing unordered lists to ordered ones

                            edit

                            With the following user style CSS:

                            ul { list-style: decimal; }
                            

                            unordered lists are changed to ordered ones. This applies (as far as the CSS selector does not restrict this) to all ul-lists in the HTML source code:

                            • those produced with *
                            • those with <ul> in the wikitext
                            • those produced by the system

                            Since each special page, like other pages, has a class based on the pagename, one can separately specify for each type whether the lists should be ordered, see Help:User contributions#User styles and Help:What links here#User styles.

                            However, it does not seem possible to make all page history lists ordered (unless one makes all lists ordered), because the class name is based on the page for which the history is viewed.

                            See also

                            edit
                            • [[Archivo:
                            1. REDIRECCIÓN Plantilla:Iconos|20px|Ver el portal sobre Lists]] Portal:Lists. Contenido relacionado con Lists.
                            • mw:Extension:Sort2: creates a list with list code only at the start and end, not per item; allows easy change of list type; sorts list


                            Wikipedia-specific help

                            edit


                            dsb:Pomoc:Lisćina hsb:Pomoc:Lisćina it:Aiuto:Liste