API

Everything it does

One class: seven options, four properties, two methods.

Constructor

import ColorLetters from '@andresclua/color-letters';

const cl = new ColorLetters({
  element: '[data-color-letters]',
  color: '#ff4d6d',
  charClass: 'c--char',
  by: 'chars',
  colors: ['#ff4d6d', '#ffd166', '#06d6a0'],
  random: false,
  ariaLabel: true,
});

Options

OptionTypeDefaultDescription
elementstring · Element · NodeList · Element[]'[data-color-letters]'What to split. A selector matches every element on the page.
colorstringnoneAny CSS color. Set as --color-letters on each element. Left unset if omitted.
charClassstring'c--char'Class added to every unit (letter or word).
by'chars' · 'words''chars'Which spans get charClass and the palette colors.
colorsstring[]nonePalette. Each unit gets --char-color, cycling through the list. An empty array is ignored.
randombooleanfalseWith colors, each unit gets a random palette color instead.
ariaLabelbooleantrueAdds a visually hidden copy of the text and hides the split spans, so screen readers read words, not letters. Skipped when the element contains links, buttons or inputs.

Properties and methods

MemberDescription
elementsThe split elements, as an array.
itemsThe spans that got charClass: letters, or words with by: 'words'.
charsEvery letter <span>, across all elements.
wordsEvery word <span>, across all elements.
setColor(color)Sets --color-letters on every element.
destroy()Restores the original HTML and removes the classes and variables it added. A new instance on the same element splits again.

What lands in the DOM

Type below to see the markup a call produces.

CSS variables

VariableSet onSet by
--color-letterselementColorLetters (color, setColor())
--char-coloreach unitColorLetters (colors)
--char-indexeach letterSplitting
--char-total · --word-totalelementSplitting
--word-indexeach wordSplitting

Claude Code skill

Use it with Claude

The package ships a skill, color-letters: a guide that helps Claude use the library in your project. Ask for an effect ("a hover trail on the hero title", "letters that fall on page change"), an option, a Nuxt or React setup, or why the colors do not show. It checks the version you have installed and never invents options.

// what is inside
skill/SKILL.md                  // rules + quick API
skill/references/api.md         // options, properties, methods, variables, markup
skill/references/recipes.md     // the 11 examples + Pagefold page transitions
skill/references/frameworks.md  // vanilla, UMD, Vue/Nuxt, React/Next, Astro, WordPress
skill/references/pitfalls.md    // symptom → cause → fix

Notes