Documents v0.10.0 · previews run the real runtime · experimental features are marked exp

length()

functionsince 0.10experimentalrequires runtime

The number of characters a person sees: grapheme clusters, so an emoji with a skin tone is 1.

On this page · 8 sections+

Syntax

length(<text>)

registry syntax: length(text)

Parameters

textstring or keywordrequired
Numbers, booleans and datetimes are an error, never converted.

Return value

A number.

Example

counter.cssreactive
.form { --value: state(""); }.form textarea:on(input) { --value: set(event(value)); }.form .count { text: length(trim(--value)); }
state()Function · hover any red tokenMakes each matching element the owner of an independent state with an initial value.Reference →

Behavior

  • Uses Intl.Segmenter. It differs from the HTML maxlength attribute, which counts UTF-16 code units.
  • In the arguments, --name reads a state; var(--name) works too.

Supported contexts

  • :on() actions: set(lower(event(value))).
  • :when() and when() conditions: :when(includes(--a, --b)).
  • Declarations, including text:: text: length(trim(--value)).

Limitations

    Experimental · syntax may change between minor versions