14

Please how to set up numbering in this format:

1) number 1
2) number 2
3) ...

in html?

I only found a way to get this format:

1. number 1
2. number 2
3. ...

No bracket after the number.

Also, is it possible to set up start, kind of numbering, but no other format.

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202

6 Answers6

25

You can achieve this with an ordered list <ol>:

ol {
    counter-reset: list;
}
ol > li {
    list-style: none;
}
ol > li:before {
    content: counter(list) ") ";
    counter-increment: list;
}
<ol>
    <li>some text</li>
    <li>some more text</li>
    <li>some further text</li>
</ol>

Sample JSFiddle

Referenced from: Ordered list (HTML) lower-alpha with right parentheses?

Ivar
  • 6,138
  • 12
  • 49
  • 61
Tanner
  • 22,205
  • 9
  • 65
  • 83
9

I know this is a little old now, but none of these solutions take into account double-digits or triple-digits or even wrapping lines of text.

*, ::after, ::before {
    box-sizing: border-box;
}

ol {
    counter-reset: list;
}

ol > li {
    list-style: none;
    position: relative;
}

ol > li:before {
    content: counter(list) ")";
    counter-increment: list;
    left: -40px;
    padding-right: 10px;
    position: absolute;
    text-align: right;
    width: 40px;
}
<ol>
    <li>Line 1</li>
    <li>Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. Line 2 is long. </li>
    <li>Line 3 is not so long.</li>
    <li>Line 4</li>
    <li>Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. Line 5 is long. </li>
    <li>Line 6 is not so long.</li>
    <li>Line 7</li>
    <li>Line 8 is long. Line 8 is long. Line 8 is long. Line 8 is long. Line 8 is long. Line 8 is long. Line 8 is long. Line 8 is long. </li>
    <li>Line 9 is not so long.</li>
    <li>Line 10</li>
    <li>Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. Line 11 is long. </li>
    <li>Line 12 is not so long.</li>
</ol>
5
<style>
ol {
columns:2;
}
ol > li::marker {
content:counter(list-item) ")\2003";
}
</style>

<ol>
<li>Hello</li>
<li>Darkness</li>
<li>My</li>
<li>Old</li>
<li>Friend</li>
<li>I<br>Have</li>
<li>Come</li>
<li>To</li>
<li>Talk</li>
<li>To</li>
<li>You</li>
<li>Again</li>
</ol>

Result:

enter image description here

user260396
  • 11
  • 1
  • 2
  • Doesn't currently work on Safari. [pen](https://codepen.io/kentr/pen/BaLqXQE), [::marker pseudo-element on caniuse](https://caniuse.com/?search=marker) – kentr Jan 13 '21 at 15:53
4

Use an ordered list:

e.g.

<ol>
<li>Coffee</li>
<li>Milk</li>
</ol> 

A more detailed explanation is available here: http://www.w3schools.com/html/html_lists.asp

If you're particularly interested in the parentheses, you can do it in css with something like this:

ol {list-style-type: none;}
li:before {content: counter(section, lower-alpha) ") ";}
li { counter-increment: section;}

Note however that this may not work perfectly in IE7 or below.

Steve
  • 329
  • 1
  • 9
0

About the closest you can come in HTML without using JavaScript (or other scripting language) is to use the CSS :before pseudoelement.

In internal styles:

<style>
li:before {
content: ") ";
}
</style>


<ol>
<li>First List Item</li>
</ol>

or if just wanting to target a certain class of <li>

li.parenthesis:before

then in html

<li class="parenthesis">First List Item</li>
user1560289
  • 29
  • 2
  • 6
0
<ul class="counter-increment">
 <li>First</li>
  <li>Second</li>
</ul>

ul.counter-increment li {
counter-increment: section;
display: table-row;
}

ul.counter-increment li::before {
content: "(" counter(section) ") ";
display: table-cell;
padding-right: 5px;
text-align: left;
}
SriB
  • 46
  • 2