Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→is-char-suitable-for-html-attr-namenext

is-char-suitable-for-html-attr-name4.2.3

Is given character suitable to be in an HTML attribute’s name?

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — ISATTRNAMECH…
  • ALSO
  • Changelog

No dependencies whatsoever. This package declares no dependencies or devDependencies.

Permalink to InstallationInstallation

Permalink to Quick TakeQuick Take

Permalink to ExamplesExamples

  • Only the first character is checked
  • Characters rejected in attribute names
  • Characters allowed in attribute names

Purpose

Checks whether the first Unicode code point can appear in an HTML attribute name. It accepts punctuation such as underscores and periods, non-ASCII letters, supplementary characters such as emoji, and non-breaking spaces. See the HTML attribute-name syntaxopens in a new tab.

The function rejects ASCII whitespace, controls, quotes, slashes, equals signs, greater-than signs, lone surrogates, and Unicode noncharacters. It also rejects the less-than sign because the HTML parser treats it as an error in attribute names. This character check does not validate a complete attribute name or determine whether an attribute has defined semantics.

API — isAttrNameChar()

The main function isAttrNameChar() is imported like this:

It’s a function which takes one input argument:

Input argumentTypeObligatoryDescription
str
Type: String
Obligatory: yes
strStringyesThe character to evaluate.

The function always returns a boolean and never throws errors.

In case of non-string input or empty string, it just returns false.

Only the first Unicode code point is checked, including both UTF-16 code units of a supplementary character. For example, "-rest" and ":rest" return true, while " rest" returns false. The rest of the string does not affect the result.

Also

If you need a comprehensive list of all possible HTML attribute names, check out html-all-known-attributes.

Permalink to changelogChangelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab