Zach’s ugly mug (his face) Zach Leatherman

<line-numbers> Web Component

Selective focus photography of a tape measure typically used for clothing
June 05, 2025

<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

Older >
Check the speedometer on the brand new Blog Awesome (now with 11ty)

Zach Leatherman IndieWeb Avatar for https://zachleat.com/is a builder for the web at Font Awesome and the creator/maintainer of IndieWeb Avatar for https://www.11ty.devEleventy (11ty), an award-winning open source site generator. At one point he became entirely too fixated on web fonts. He has given 85 talks in nine different countries at events like Beyond Tellerrand, Smashing Conference, Jamstack Conf, CSSConf, and The White House. Formerly part of CloudCannon, Netlify, Filament Group, NEJS CONF, and NebraskaJS. Learn more about Zach »

Shamelessly plug your related post

These are webmentions via the IndieWeb and webmention.io.

Sharing on social media?

This is what will show up when you share this post on Social Media:

How did you do this? I automated my Open Graph images. (Peer behind the curtain at the test page)