Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

minlength / maxlength

Length limits for text fields and textareas: maxlength stops typing at the limit, minlength makes a too-short value invalid. Vanilla Breeze adds a live counter and custom messages.

Overview

maxlength sets the most characters a user can enter: the browser stops accepting input at the limit and truncates pastes. minlength sets the fewest: a shorter, non-empty value is invalid (validity.tooShort) and blocks submission. Both count UTF-16 code units, and both are checked against what the user typed, not what a script wrote.

Applies to: <textarea> and <input> of type text, search, url, tel, email and password. Not number, date or other types; use min and max there.

Values

AttributeValueEffect
maxlengthInteger ≥ 0The user can't enter more. A value over the limit (set by script or the server) is accepted but becomes tooLong once the user edits it.
minlengthInteger ≥ 0, not above maxlengthA user-edited, non-empty value shorter than this is tooShort.
EitherAbsent, negative or not an integerNo limit (the default). The DOM properties maxLength and minLength return -1.

An empty field passes minlength. Add required when it must be filled.

Examples

Exact length

Set both to the same number for a fixed-length code, and add pattern if the characters matter.

Password length

Set a minimum and leave the maximum generous (or absent). A low maxlength on a password silently truncates pasted passphrases from a password manager.

Word limits

There is no native word limit. data-count="words" with data-maxwords shows a word count and warns, but does not make the field invalid; keep a maxlength for a hard cap.

In Vanilla Breeze

  • data-count on a <textarea> adds a counter below it that reads its limit from maxlength ("40 of 160 characters"). The counter turns to a warning colour at 80% and to bold error colour at the limit, is linked with aria-describedby, and announces the count through a polite live region near the limit (src/utils/textarea-count-init.js). Inside <form-field>, the field keeps the counter in the control's aria-describedby list next to the hint.
  • Messages. data-message-tooshort and data-message-toolong on the control set the text in output.error (src/web-components/form-field/logic.js).
  • data-mask sets maxlength to the mask's length when you haven't.
  • OTP fields. input[data-type="otp"] in a <form-field> sets maxlength to its data-length (default 6).
  • Components. <chat-input> takes a maxlength (default 4000) and refuses to send a longer message. <markdown-editor> adopts your authored <textarea> with its minlength and maxlength, so the native limits apply.

Accessibility

  • State the limit in visible text before the user hits it. A field that silently stops accepting characters is confusing, especially for screen-reader users who don't see the text stop growing. The data-count counter and an output.hint both do this.
  • Make the tooShort message say how many characters are needed.
  • Don't truncate data the user can't see: a maxlength lower than real names, addresses or passwords causes silent data loss.

Gotchas

  • Code units, not characters. An emoji such as 👍 counts as 2, and a flag or family emoji as more. Allow headroom on fields where people type emoji.
  • Only user edits are checked. A value set by script or rendered by the server can be longer or shorter than the limits without being invalid, until the user edits it. Validate on the server.
  • Before Safari 17, a line break in a textarea counted as two characters toward maxlength.
  • The browser enforces maxlength while typing even with novalidate; that attribute only affects submit-time checks.
  • minlength greater than maxlength is an authoring error; the field can never be valid.

Related

Which to choose

  • maxlength — a hard cap the backend relies on.
  • minlength — a minimum that makes the value meaningful (passwords, descriptions).
  • data-count — whenever a textarea has a limit, so users see it coming.
  • pattern — the characters matter, not just how many.
↑