<line-numbers> is a lightweight web component that adds line numbers to <pre> and <textarea> elements. It even dynamically updates with <textarea> input.
<pre> and <textarea> elements--uln-number-type custom propertystart attribute1. Install <line-numbers> and import it into your document.
# NPM $ npm install @zachleat/line-numbers
<script type="module" src="./line-numbers.js"></script>
2. Wrap your target element with <line-numbers>:
<!-- Pre -->
<line-numbers>
<pre>
const greet = () => {
console.log("Hello, world!");
};
</pre>
</line-numbers> <!-- Textarea -->
<line-numbers>
<textarea>
Initial text in the area.
Add more lines here.
</textarea>
</line-numbers> 3. Custom starting index:
<line-numbers start="10"> <pre>// Code starts at line 10</pre> </line-numbers>
4. Obtrusive mode (line numbers take up layout space):
<line-numbers start="10"> <pre>// Code starts at line 10</pre> </line-numbers>
5. Disable the automatic input event listener on a <textarea>. You would then need to call the render() method on the element yourself to update the line numbers.
<line-numbers manual-render> <pre>// Code starts at line 10</pre> </line-numbers>
document.querySelector('line-numbers').render(); 6. Available CSS variables to customize the line numbers:
--uln-number-type: Change counter style (decimal, roman, etc.)--uln-color: Line number text color--uln-font: Line number font properties--uln-padding-h: Horizontal padding for line numbers--uln-padding-v: Vertical padding for line numbersThe post Add Numbering to Pre and Textarea – line-numbers Web Component appeared first on CSS Script.
Microsoft Detection and Response Team details a sophisticated voice phishing (vishing) campaign that successfully compromised…
Jacob Drouin, a former Franklin police officer, is suing the city and its police department…
Winnebago County voters said "no" to a new 1% sales tax to fund school improvements,…
ROCKFORD, Ill. (WTVO) — The Community Action Garden grants are now available for all neighborhood,…
Illinois Lt. Gov. Juliana Stratton, backed by Gov. J.B. Pritzker, will face Republican Don Tracy…
The U.S. Capitol on March 3, 2026. (Photo by Jennifer Shutt/States Newsroom)WASHINGTON — U.S. Senate…
This website uses cookies.