Search code examples
htmlcsscss-counter

Unordered List with numbers instead of bullet points


I have a Terms and Conditions file that I need to get on the webiste. However there are a lot of clauses and points such as 2, 2.1, 2.1.1 etc.

I thought I could do an unordered list and use css to get rid of the bullet points. I realize it may seem a bit long-winded but I am no HTML expert and I am also not sure how to go about it.


Solution

  • Try using counters.

    ol {
      counter-reset: item;
    }
    li {
      display: block;
    }
    li:before {
      content: counters(item, ".")". ";
      counter-increment: item;
    }
    <ol>
      <li>test</li>
      <li>test</li>
      <ol>
        <li>testing</li>
        <li>testing</li>
      </ol>
    </ol>

    This will produce:

    1. test
    2. test

      2.1. testing

      2.2. testing

    Read more here: https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Counters