Questions tagged [html-lists]

Used for ordered and unordered lists and their list items in HTML, and also any list styles applied to them.

Lists in HTML can be either ordered (typically numbered, using the <ol> tag) or unordered (typically bulleted, using the <ul> tag) and can contain any number of list items (<li>), which could also contain nested lists within them.

Any time you are listing things which should follow a logical order, such as instructions, you should use an ordered list. Any time you are listing things in which the order doesn't matter, such as your grocery list, you should use an unordered list.

Ordered List

<ol>
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
</ol>

Output

  1. Item 1
  2. Item 2
  3. Item 3

Unordered List

<ul>
   <li>Item 1</li>
   <li>Item 2</li>
   <li>Item 3</li>
</ul>

Output

  • Item 1
  • Item 2
  • Item 3

Nesting Lists

Here's an example of how lists should be nested within each other:

<ul>
  <li>Test</li>
  <li>Items
    <ul>
      <li>Test</li>
    </ul>
  </li>
  <li>Test Test
    <ul>
      <li>Test</li>
    </ul>
  </li>
</ul>

Output

  • Test
  • Items
    • Test
  • Test Test
    • Test

Notice how a nested list is part of a list item. Another list cannot be (semantically) opened directly inside a list, it must be opened within one of its list items.

Styling Lists

There are several styles which can be used in order to determine how lists will appear. The default values of each style property are italicized.

  • list-style-position: inside, outside, or inherit
    Determines where the bullets or numbering will appear within the list. If set to inside, they will appear inline at the beginning of each item. If set to outside, they will appear outside, where each number or bullet is aligned to the right and pushed outside the actual list.

  • list-style-image: url, none, inherit
    Defines an image to be used for the bulleting of the list rather than a standard text number or bullet. If the image cannot be loaded, it will fall back to the type which is defined for the list.

  • list-style-type
    Defines what type of bulleting or numbering to use for the list. The default is different depending on whether it's ordered or unordered. All of the following are valid list types which you can use:

    • armenian
    • circle
    • cjk-ideographic
    • decimal (Default for ordered lists)
    • decimal-leading-zero (01, 02, 03, etc)
    • disc (Default for unordered lists)
    • georgian
    • hebrew
    • hiragana
    • hiragana-iroha
    • inherit
    • katakana
    • katakana-iroha
    • lower-alpha (a, b, c, etc)
    • lower-greek
    • lower-latin (Same as lower-alpha)
    • lower-roman (i, ii, iii, etc)
    • none
    • square
    • upper-alpha (A, B, C, etc)
    • upper-latin (Same as upper-alpha)
    • upper-roman (I, II, III, etc)
  • list-style
    Allows you to define all three of the above in one declaration, in the order: list-style-type, list-style-position, then list-style-image. You can also set it to inherit or none to set all three properties to inherit or none.

Description Lists (Definition Lists)

<dl> description list, <dt> term (name), and <dd> value (description) tags can be used to create a lists which associate specific names with values. For instance in a receipe:

<dl>
 <dt>Castor Sugar</dt>
  <dd>Finely granulated white sugar.</dd>
 <dt>Self-raising flour</dt>
  <dd>A pre-mixed combination of flour and leavening agents (usually salt and baking powder).
  </dd>
 </dl> 

Output

Castor Sugar
  Finely granulated white sugar.
Self-raising flour
  A pre-mixed combination of flour and leavening agents (usually salt and baking powder).

References

W3C HTML lists

List examples

Contextual styles and Bootstrap lists

5634 questions
545
votes
7 answers

Proper way to make HTML nested list?

The W3 docs have a nested list example prefixed by DEPRECATED EXAMPLE:, but they never corrected it with a non-deprecated example, nor explained exactly what is wrong with the example. So which of these ways is the correct way to write an HTML…
Ricket
  • 31,028
  • 28
  • 106
  • 137
527
votes
16 answers

How to set Bullet colors in UL/LI html lists via CSS without using any images or span tags

Imagine a simple unsorted list with some
  • items. Now, I have defined the bullets to be square shaped via list-style:square; However, if I set the color of the
  • items with color: #F00; then everything becomes red! While I only want to set…
  • Sam
    • 15,156
    • 23
    • 85
    • 134
    290
    votes
    14 answers

    How to keep indent for second line in ordered lists via CSS?

    I want to have an "inside" list with list bullets or decimal numbers being all flush with superior text blocks. Second lines of list entries have to have the same indent like the first row! E.g.: Lorem ipsum dolor sit amet, consectetuer adipiscing…
    kernfrucht
    • 2,978
    • 2
    • 13
    • 10
    250
    votes
    5 answers

    How to markdown nested list items in Bitbucket?

    I'm trying to see my markdown nested list items rendered with corresponding indentation when viewed in a browser live from the Bitbucket pages. But I can't figure out how it works even when using their examples (updated): * Item 1 * Item 2 * Item 3 …
    Jeff Puckett
    • 28,726
    • 15
    • 96
    • 149
    247
    votes
    17 answers

    How to display an unordered list in two columns?

    With the following HTML, what is the easiest method to display the list as two columns?
    • A
    • B
    • C
    • D
    • E
    Desired display: A B C D E The solution needs to work with Internet…
    atp03
    • 2,939
    • 3
    • 15
    • 20
    240
    votes
    20 answers

    HTML list-style-type dash

    Is there a way to create a list-style in HTML with a dash (i.e. - or – – or — —) i.e.
    • abc
    Outputting: - abc It's occurred to me to do this with something like li:before { content: "-" };, though I don't know the…
    Brian M. Hunt
    • 71,376
    • 65
    • 208
    • 328
    203
    votes
    21 answers

    CSS: Control space between bullet and
  • I'd like to control how much horizontal space a bullet pushes its
  • to the right in an
      or
        . That is, instead of always having * Some list text goes here. I'd like to be able to change that to be * Some list text goes …
  • erjiang
    • 40,940
    • 10
    • 57
    • 94
    176
    votes
    14 answers

    Getting rid of bullet points from

    I have the following list:
    • Benz
    • Other Benz
    • Other Other Benz
    I want to get rid the bullets so i tried: ul#otis { list-style-type: none; } That didn't work though. What is the proper way to…
    Sam Khan
    • 2,177
    • 4
    • 16
    • 16
    175
    votes
    3 answers

    Removing ul indentation with CSS

    I cannot seem to remove the indent from my unordered list when long lines in my list wrap around. Here is what my list looks like: Windows users can use putty Mac users can use the Terminal.app Linux users can use SSH userid@ourserver.com port…
    solerous
    • 1,991
    • 2
    • 12
    • 14
    174
    votes
    17 answers

    Adjust list style image position?

    Is there a way to adjust the position of list-style-image? When I use padding for list items the image will stay at its position and won't move with padding...
    datisdesign
    • 3,005
    • 7
    • 25
    • 29
    167
    votes
    7 answers

    Custom li list-style with font-awesome icon

    I am wondering if it's possible to utilize font-awesome (or any other iconic font) classes to create a custom
  • list-style-type? I am currently using jQuery to do this, ie: $("li.myClass").prepend("
    Darrrrrren
    • 5,308
    • 5
    • 28
    • 49
  • 163
    votes
    6 answers

    Is div inside list allowed?

    I know that DIV inside LI isn't allowed, but I've seen it lately on many "big" websites like Smashing Magazine, Web Designer Wall... etc. I tried to validate sites, and they have errors, but nothing about DIV in LI?! So can I use it inside LI, and I…
    Kenan
    • 1,655
    • 2
    • 10
    • 5
    150
    votes
    10 answers

    How do I set vertical space between list items?

    Within a
      element, clearly the vertical spacing between lines can be formatted with the line-height attribute. My question is, within a
        element, how do I set the vertical spacing between the list items?
    Brice Coustillas
    • 1,837
    • 2
    • 11
    • 16
    138
    votes
    4 answers

    What are the allowed tags inside a
  • ?
  • I have been searching for the list of tags that are available inside a
  • , but I couldn't find any reference. Is it possible that any standards-compliant HTML 4+ block element is allowed in them?
  • petsagouris
    • 1,685
    • 2
    • 12
    • 13
    137
    votes
    9 answers

    Is there a way to break a list into columns?

    My webpage has a 'skinny' list: for example, a list of 100 items of one word in length each. To reduce scrolling, I want to present this list in two or even four columns on the page. How should I do this with CSS?
    • Item
    user776676
    • 3,985
    • 13
    • 53
    • 76
    1
    2 3
    99 100