data-lorem prototype
Placeholder text via data attributes. Fill any element with lorem ipsum, specify word counts, sentence counts, or list items. Auto-detects language for CJK, Arabic, and Cyrillic corpuses.
Overview
The data-lorem attribute fills any text-containing element with placeholder text. Built-in corpuses for Latin, CJK, Arabic, and Cyrillic keep the browser bundle lean (~4KB) without requiring external dependencies.
How It Works
- On
DOMContentLoaded, finds all elements withdata-lorem - Parses the attribute value to determine word count, sentence count, or mode
- Detects the appropriate corpus from the element's
langattribute (or its ancestors) - Fills the element's
textContent(orinnerHTMLfor list items) - Marks the element with
data-lorem-filledandtranslate="no" - A MutationObserver watches for dynamically added elements
Attributes
| Attribute | Type | Description |
|---|---|---|
data-lorem |
string | Controls output. See Values table below. |
data-lorem-filled |
boolean | Set automatically after content is injected. Used as CSS hook for wireframe integration. |
data-lorem-init |
boolean | Set automatically to prevent double-binding. Do not set manually. |
Values
| Value | Result | Example |
|---|---|---|
| (empty) | ~50 words of lorem ipsum | <p data-lorem></p> |
50 | 50 words | <p data-lorem="50"></p> |
3 sentences | 3 full sentences | <p data-lorem="3 sentences"></p> |
heading | 5 words (heading-length) | <h2 data-lorem="heading"></h2> |
5 items | 5 <li> elements (on <ul>/<ol>) | <ul data-lorem="5 items"></ul> |
cjk | CJK placeholder corpus | <p data-lorem="cjk"></p> |
arabic | Arabic placeholder corpus | <p data-lorem="arabic"></p> |
cyrillic | Cyrillic placeholder corpus | <p data-lorem="cyrillic"></p> |
Word Count
Pass a number to get that many words.
Sentence Count
Use N sentences for full sentences (singular sentence also works).
Headings
Use heading for short, heading-length text (5 words).
List Items
On <ul> or <ol>, use N items to generate <li> elements.
Multi-language Support
The corpus auto-detects from the lang attribute on the element or any ancestor. You can also force a specific corpus by name.
| Language codes | Corpus |
|---|---|
ja, zh, ko | CJK (Chinese/Japanese/Korean) |
ar, fa, ur, he | Arabic |
ru, uk, bg, sr | Cyrillic |
| any other / none | Latin (default) |
Production Transition
Replace the content and remove data-lorem. No structural changes needed.
Wireframe Integration
In data-wireframe="lo" mode, elements with data-lorem-filled get abstract text-block styling: extra letter-spacing and reduced opacity.
Dynamic Elements
Elements added to the DOM after page load are automatically filled via a MutationObserver.
Accessibility
- Sets
translate="no"on filled elements so translation tools skip placeholder text - Does not set
aria-hidden— screen readers should still read placeholder content during testing to verify document structure - Filled list items use semantic
<li>elements