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

Quick Take

import { strict as assert } from "assert";
import { isAttrNameChar } from "is-char-suitable-for-html-attr-name";

// Follows the spec:

assert.equal(isAttrNameChar("a"), true);
assert.equal(isAttrNameChar("?"), false);


It's a function which validates strings (first character of it), is it suitable to be in an HTML attribute's name. See the official spec opens in a new tab for HTML attribute names.

API - Input


In other words, function which takes one string argument:

Input argument Key value's type Obligatory? Description
str String yes The character to evaluate.

This program does not throw. It just returns false.

If the input string is longer than 1, its first character is used.

Zero-length string yields false, same like non-string type values.

API - Output

Boolean, true or false. Erroneous input arguments will yield false as well.


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


See it in the monorepo opens in a new tab, on GitHub.


To report bugs or request features or assistance, raise an issue on GitHub opens in a new tab.

Any code contributions welcome! All Pull Requests will be dealt promptly.


MIT opens in a new tab

Copyright © 2010–2021 Roy Revelt and other contributors

Related packages:

📦 html-all-known-attributes 5.0.1
All HTML attributes known to the Humanity
📦 emlint 5.0.1
Pluggable email template code linter
📦 html-crush 5.0.1
Minifies HTML/CSS: valid or broken, pure or mixed with other languages
📦 stristri 4.0.1
Extracts or deletes HTML, CSS, text and/or templating tags from string
📦 string-strip-html 9.0.1
Strips HTML tags from strings. No parser, accepts mixed sources
📦 detect-is-it-html-or-xhtml 5.0.1
Answers, is the string input string more an HTML or XHTML (or neither)
📦 detect-templating-language 3.0.1
Detects various templating languages present in string