Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Custom list-item counter</h1>

<p>(the experiment was first done in December 21, 2017, it seems that today (October 2021) things are mostly fixed everywhere, hooray!)</p>

<p>Why this should work, a quote <a href="https://www.w3.org/TR/css-lists-3/#declaring-a-list-item">from the specs</a>:</p>

<blockquote>Additionally, list items automatically increment the special list-item counter. Unless the counter-increment property manually specifies a different increment for the list-item counter, it must be incremented by 1 on every list item, at the same time that counters are normally incremented.</blockquote>

<h2>With a <code>start</code> attribute</h2>

<ol start="30">
  <li>a</li>
  <li>
<ol reversed>
  <li>a</li>
  <li>b</li>
  <li>c</li>
</ol>
    
  </li>
  <li>c</li>
</ol>

<ul>
  <li><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=288704">No support in Firefox</a></li>
  <li><a href="https://bugs.chromium.org/p/chromium/issues/detail?id=796961">Chrome</a>/<a href="https://bugs.webkit.org/show_bug.cgi?id=181084">Safari</a> start from an incorrect incremented state.</li>
  <li>Works perfectly in Edge!</li>
  <li>Safari fixed later</li>
</ul>

<h3>Fix for Chrome</h3>

<ol start="30" class='fix'>
  <li value="30">a</li>
  <li>b</li>
  <li>c</li>
</ol>

<ul>
  <li>replaced `start` on the `ol` with `value` on the first item</li>
  <li>Though, no reason not to keep the start attr?</li>
</ul>

<h2>Using <code>value</code> attribute</h2>


<ol>
  <li>a</li>
  <li>b</li>
  <li value='30'>c</li>
  <li>d</li>
  <li value='35'>e</li>
  <li>f</li>
</ol>

<ul>
  <li>The value attribute works ok in Chrome</li>
  <li>But the list without value is buggy</li>
</ul>


<h3>Fix for Chrome</h3>
<ol class='fix'>
  <li value='1'>a</li>
  <li>b</li>
  <li value='30'>c</li>
  <li>d</li>
  <li value='35'>e</li>
  <li>f</li>
</ol>

<ul>
  <li>Just added `value="1"` for the first list item</li>
</ul>


<h3>Added inline CSS for Fx</h3>
<ol class='fix'>
  <li value='1' style='counter-reset: list-item 1;'>a</li>
  <li>b</li>
  <li value='30' style='counter-reset: list-item 30;'>c</li>
  <li>d</li>
  <li value='35' style='counter-reset: list-item 35;'>e</li>
  <li>f</li>
</ol>

<ul>
  <li>Added counter-resets for list-items, so works in Fx</li>
  <li>But become broken in Safari, lol</li>
  <li>So this fix should go only to Fx, probably via variable, to allow conditional appliance?</li>
</ul>




<h3>Final fix?</h3>
<ol class='fix'>
  <li value='1' style='--fx-value: 1'>a</li>
  <li>b</li>
  <li value='30' style='--fx-value: 30;'>c</li>
  <li>d</li>
  <li value='35' style='--fx-value: 35;'>e</li>
  <li>f</li>
</ol>

<ul>
  <li>Using a variable for counter-reset in Fx, inside a @supports hack</li>
  <li>Other browsers would ignore variable</li>
  <li>(would need to test nested lists, maybe would need to reset the variable on the `ol`?)</li>
  <li>(also, should re-test in edge)</li>
  <li>(also: if we have a control over the style attr, and can use counter-reset already, we can throw away the automatic list counter anyway -_-)</li>
</ul>

<h2>Hard level: reversed, lol</h2>
              
            
!

CSS

              
                ol > li::before {
  content: "(" counter(list-item) ") ";
}

ol > li:not([value]) {
  counter-increment: list-item 1;
}

/* Fix for Fx */
@supports (-moz-appearance:meterbar) {
  ol > li {
  /* would be better, if was supported */
  /* counter-reset: list-item attr(value number); */
    
    counter-reset: list-item var(--fx-value);
  }
}

/* Prettier with grids! */
body {
  font: 18px/1.5 Helvetica Neue, Arial, sans-serif;
  display: grid;
  grid-template-columns: 1fr repeat(2, minmax(0, 20em)) 1fr;
}

body > * { grid-column: 2/span 2; }
ol { grid-column: 2; }
ul { grid-column: 3; }


              
            
!

JS

              
                
              
            
!
999px

Console