Zach’s ugly mug (his face) Zach Leat­herman

<line-numbers> Web Component

Selective focus photography of a tape measure typically used for clothing
June 05, 2025
🚾Web Component@zachleat/line-numbers

A web component to add line numbers next to various HTML elements.

All🚾 0.1%
Popularity
cdn3k Monthly jsDelivr CDN hits sparkline for @zachleat/line-numbers, ranging 45 to 913
Versions
4 versions in
1.0.3
Audit
0 reports
0 deps
Issues
3
PRs
0

<line-numbers> is a web component to add line numbers alongside <pre> or <textarea> elements.

Install:

npm install @zachleat/line-numbers

Features

  • <pre> supported
  • <textarea> supported (even when adding or removing lines)
  • CSS overflow supported (with obtrusive/visible or nonobtrusive scrollbars)
  • Numbers are excluded from content flow (not selectable, important for copy paste components!)
  • Use any CSS counter style via custom property --uln-number-type
  • Change the starting index for counter via (<line-numbers start="999">)
  • Numbers are unobtrusive by default to reduce layout shift (opt-in to obtrusive behavior via <line-numbers obtrusive>)

Limitations

Trying to keep this one as simple as possible, so please note the following:

  • Line wrapping is not supported (white-space: pre or white-space: nowrap only, and this is enforced by the component)
  • Elements using contenteditable are not supported

IndieWeb Avatar for https://unsplash.com/Poster image by Siora Photography

Zach Leatherman is a builder for the web at Font Awesome and the creator of Build Awesome (née Eleventy/11ty), an award-winning open source website generator. He measures website performance with speedlify and at one point became too fixated on web fonts. He has given 86 talks in nine different countries at events like Beyond Tellerrand, Smashing Conference, Jamstack Conf, CSSConf, and The White House. Learn more about Zach »