StringTune/Docs

Modules

DOM Output

What wrappers, attributes, classes, text nodes, and CSS variables StringSplit actually writes.

Type
Built-in module
Status
Stable
Scope
Element-level
Activation
string="split"

DOM Output

The public contract of StringSplit is the rebuilt DOM tree. This page documents every wrapper, class, attribute, and CSS variable the module produces.

Generated Wrappers

WrapperCreated when
span.-s-lineline, word-line, or char-line is present
span.-s-wordword, word-line, or char-word is present
span.-s-charchar, char-line, or char-word is present

Source Element

After splitting, the source element receives:

OutputDescription
class -splittedMarks that the element has been processed
aria-labelOriginal text content for accessibility
string-split-originalCached original HTML (runtime-owned, do not modify)

If string-split-restore-after fires later:

OutputDescription
class -restoredMarks that the original HTML was restored

CSS Variables On Wrappers

.-s-line

VariableAlwaysDescription
--line-indexyes0-based line index
--word-totalyesNumber of words in this line
--fit-font-sizewhen fit + line splitComputed font size to fill container width
--line-startwhen line[start]Index from the beginning
--line-centerwhen line[center]Distance from center
--line-endwhen line[end]Index from the end
--line-randomwhen line[random()]Random value

.-s-word

VariableAlwaysDescription
--word-indexyesGlobal 0-based word index
--char-totalyesNumber of chars in this word
--word-startwhen word[start]Global word index
--wordLine-startwhen word-line[start]Per-line word index
etc.Other alignment combinations follow the same pattern

.-s-char

VariableAlwaysDescription
--char-indexyesGlobal 0-based char index
--kerningwhen neededKerning delta with the next character (also applied as margin-right)
--char-startwhen char[start]Global char index
--charWord-startwhen char-word[start]Per-word char index
--charLine-centerwhen char-line[center]Per-line distance from center
etc.Other alignment combinations follow the same pattern

Source Element Variables

VariableWhenDescription
--char-global-totalchar wrappers activeTotal char count
--word-global-totalword wrappers activeTotal word count
--line-global-totalline wrappers activeTotal line count
--fit-font-sizefit without line splitComputed font size for the widest line
--fit-scale-yfit without line splitViewport height / text height ratio
--fit-aspect-ratiofit without line splitContainer width / text height ratio

Wrapper Attributes

Every generated wrapper (.-s-line, .-s-word, .-s-char) receives:

  • aria-hidden="true" — so screen readers skip individual wrappers
  • data-split-content — the text content of that wrapper

Nesting Order

When multiple wrapper levels are active, nesting follows this order:

TEXT
.-s-line
  └─ inline elements (em, strong, a, span...)
       └─ .-s-word
            └─ .-s-char

Inline HTML elements from the source (like <em> or <a>) are reconstructed between line and word wrappers. They keep their original tag and attributes so your CSS selectors continue to work.

Spaces And Line Breaks

  • Spaces and tabs are not wrapped in .-s-char spans
  • Inter-word spacing uses \u00a0 (non-breaking space) text nodes between words
  • When line wrappers are active, <br> is inserted between lines
  • Char-based animation only applies to visible characters, not spaces

Helper Classes

-before-element

Applied to a wrapper whose content sits immediately before an inline element like <img>.

-after-element

Applied to a wrapper whose content sits immediately after an inline element.

These classes appear on the relevant .-s-line, .-s-word, or .-s-char wrapper depending on which levels are active. Use them to adjust spacing or animation timing near embedded elements.

split-class Classes

When you use <split-class class="is-accent">...</split-class> in the source, those classes appear on the generated wrappers:

  • If every char in a word has the same split-class, the classes are hoisted to the .-s-word wrapper
  • Otherwise, they appear on individual .-s-char wrappers

Kerning

When char wrappers are active, the runtime measures kerning between adjacent characters. If a meaningful kerning delta is detected, it writes:

  • --kerning CSS variable
  • margin-right: var(--kerning) inline style

This preserves the visual tightness/looseness of the original typeface after splitting characters into individual spans.

Opaque Elements

Elements like <img>, <svg>, <video>, and <table> inside the source are inserted into the output as-is:

  • They do not get .-s-word or .-s-char wrappers
  • They do not receive index variables
  • They do occupy a slot in the word/char index sequence — the next word after an image will have an incremented index

See Inline HTML for the full list.