Options

Marshall Lochbaum edited this page Apr 21, 2018 · 39 revisions

Valid option values are listed in bullet points, or explicitly specified. If no values are specified, then the option is boolean and has only the valid values true and false. If no default is specified, the default value is true.

The value false is valid for any option. If used, that option does not provide restrictions on the html input.

The following values may be used for format specifiers. A format specifier is a requirement on the form of a string.

  • "lowercase": Consists of lowercase letters.
  • "underscore": Lowercase and underscore-separated.
  • "dash": Lowercase and separated by hyphens.
  • "camel": camelCase (or CamelCase).
  • "bem": The BEM (block, element, modifier) syntax.
  • An arbitrary Javascript RegExp object.
  • A string matching Javascript's RegExp format (like '/^[a-z]+$/g').

Each of the named formats allows digits to be used in addition to letters after the first letter in each word. See lib/process_option.js for the actual regular expressions attached to these options.

attr-bans

Default: ['align', 'background', 'bgcolor', 'border', 'frameborder', 'longdesc', 'marginwidth', 'marginheight', 'scrolling', 'style', 'width']

The value of this option is a list of strings, each of which is an attribute name. Attributes with any of the given names are disallowed.

attr-name-ignore-regex

Default: false

A string giving a regular expression, a RegExp object, or false. If set, attrs with names matching the given regular expression are ignored for the attr-name-style rule. For example, excluding {{...}} names used by Angular and other templating methods can be done with the regex {{.*?}}.

attr-name-style

Default: "dash"

A format specifier, or false. If set, attribute names must conform to the given format.

attr-new-line

Default: false

A non-negative integer, or "+0". If set, no more than this number of attributes may be on the same row. A value of 0 applies only to the first row, restricting subsequent rows to one element, and a value of "+0" is the same but allows an attribute to be on the first row if there is only one attribute.

attr-no-dup

If set, the same attribute name cannot be repeated within a single tag.

attr-no-unsafe-char

If set, unsafe characters may not be used in attribute values. The unsafe characters are those whose unicode values lie in the ranges 0000-0009, 000b-000c, 000e-001f, 007f-009f, 00ad, 0600-0604, 070f, 17b4, 17b5, 200c-200f, 2028-202f, 2060-206f, feff, fff0-ffff.

attr-order

Default: false

A list of attribute names, or false. If set, any attributes present in the list must be ordered as they are in the list.

attr-quote-style

Default: "double"

  • "double": Attribute values must be quoted using double quotes.
  • "single": Attribute values must be quoted using single quotes.
  • "quoted": Attribute values must be quoted.
  • false: No restriction.

Applies only to attributes with values (including the empty quoted values '' and ""). To catch attributes with no values, use attr-req-value.

attr-req-value

If set, attribute values cannot be empty. This does not disallow the value "".

Boolean attributes such as hidden and checked do not require values, but no attribute may have an equals sign but no value after it, like <div class=></div>, as this is invalid html.

attr-validate

If set, attributes in a tag must be well-formed.

class-no-dup

If set, the same class name cannot be repeated within a class attribute.

class-style

Default: false

A format specifier, "none", or false. If set, classes must fit the given format. If false, the value for id-class-style is used instead (use 'none' to avoid matching anything).

Note that there is no symmetric id-style option. This maintains compatibility with older versions of htmllint and allows a user to set both id and class styles with a single option in the common case that they are the same. To use different styles, set the class style with class-style and the id style with id-class-style.

doctype-first

Default: false

  • true: The doctype (<!DOCTYPE ... >) must be the first element in the file, excluding comments and whitespace.
  • "smart": If a head tag is present in the document, then the doctype must come first.
  • false: No restriction.

doctype-html5

Default: false

If set, the doctype element must specify html5.

fig-req-figcaption

Default: false

If set, each figure tab must contain a figcaption child and each figcaption tag's parent must be a figure.

focusable-tabindex-style

Default: false

If set, all focusable elements (a, area, button, input, img, select, textarea) must have a positive tabindex attribute, if any.

Reasoning: IITAA, 10.3 and 10.4

head-req-title

If set, any head tag in the page must contain a non-empty title tag.

head-valid-content-model

If set, the content-model of the HEAD element will be enforced: only base, link, meta, noscript, script, style, template, and title tags are legal children.

href-style

Default: false

  • "absolute": All href tags must use absolute URLs.
  • "relative": All href tags must use relative URLs.
  • false: No restriction.

html-req-lang

Default: false

If set, each html tag must have a lang attribute.

html-valid-content-model

If set, the content-model of the html element will be enforced: at most one head and one body tag may appear, in that order. No other tags are allowed.

id-class-ignore-regex

Default: false

The value is either a string giving a regular expression or false. If set, ids and classes matching the given regular expression are ignored for the id-class-style rule. For example, excluding {{...}} classes used by Angular and other templating methods can be done with the regex {{.*?}}.

id-class-no-ad

If set, values for the id and class attributes may not use the word "ad", "banner", or "social". This rule only bans those words when not adjacent to other alphanumeric characters. Thus words like "gradient" are still allowed.

id-class-style

Default: "underscore"

A format specifier, or false. If set, ids and classes must fit the given format. May be overridden by class-style for classes.

id-no-dup

If set, values for the id attribute may not be duplicated across elements.

img-req-alt

  • true: Each img tag must have a non-empty alt property.
  • "allownull": Each img tag must have an alt property with a value, but value may be null (equal to "").
  • false: No restriction.

img-req-src

If set, a source must be given for each img tag.

indent-delta

Default: false

If set, check wether or not two consecutive lines have an indentation delta in the range [-1, 1].

indent-style

Default: "nonmixed"

  • "tabs": Only tabs may be used for indentation.
  • "spaces": Only spaces may be used for indentation.
  • "nonmixed": Either tabs or spaces may be used, but not both in the same file.
  • false: No restriction.

indent-width

Default: 4

The value of this option is either false or a positive integer. If it is a number and spaces are used for indentation, then spaces used to indent must come in multiples of that number.

indent-width-cont

Default: false

If set, ignore indent-width for lines whose first non-whitespace character is not <. This is known as continuation indent because it enables the user to continue tags onto multiple lines while aligning the attribute names.

input-radio-req-name

If set, each radio-type input must have a nonempty name attribute.

input-req-label

Default: false

If set, each text or radio input element must have an associated label element. The label may be a parent of the input element, or may identify the element it labels using its for attribute, which must match the input's id (or name, for text inputs) attribute.

label-req-for

If set, each label tab must have a for attribute. This practice helps screen readers, and improves form element selection by allowing the user to focus an input by clicking on the label.

See MDN: label element and MDN: How to structure an HTML form.

lang-style

Default: "case"

If set, the lang tag must have a valid form (xx-YY, where xx is a valid language code and YY is a valid country code). If the value is equal to "case", the tag must be capitalized conventionally (with the language code lowercase and the country code uppercase).

line-end-style

Default: "lf"

Line endings must conform to the given style.

  • "lf": Unix style, ending in LF.
  • "crlf": Windows style, ending in CRLF.
  • "cr": Ending in CR.
  • false: No restriction.

line-max-len

Default: false

The value of this option is either false or a positive integer. If it is a number, the length of each line must not exceed that number.

line-max-len-ignore-regex

Default: false

A string giving a regular expression, a RegExp object, or false. If set, lines with names matching the given regular expression are ignored for the line-length rule. For example, lines with long href attributes can be excluded with regex href.

line-no-trailing-whitespace

If set, lines may not end with whitespace characters.

link-req-noopener

If set, each a tag with target="_blank" must have a rel="noopener" or rel="noreferrer" attribute.

maxerr

Default: false

A nonnegative integer, or false. If it is a positive integer, limit output to at most that many issues.

raw-ignore-regex

Default: false

A string giving a regular expression, a RegExp object, or false. If set, text matching the given regular expression is removed before any parsing or linting occurs. This option cannot be configured in-line, but it can be set to a value such as /\<\!-- htmllint ignore --\>[^]*?\<\!-- htmllint unignore --\>/ to allow some control using comment tags.

spec-char-escape

If set, special characters in text and attributes (e.g. >) must be escaped.

table-req-caption

Default: false

If set, each table must contain at least one caption tag.

table-req-header

Default: false

If set, each table tag must contain a header: a thead tag or a tr tag with a th child.

tag-bans

Default: ['style', 'b', 'i']

The value of this option is a list of strings, each of which is a tag name. Tags with any of the given names are disallowed.

tag-close

If set, tags must be closed. Because htmlparser2 does not match tags case-insensitively, tags whose closing tag has a different case than the opening tag may be detected by this option rather than tag-name-match.

tag-name-lowercase

If set, tag names must be lowercase. Only the opening tag is checked; mismatches between open and close tags are checked by tag-name-match.

tag-name-match

If set, tag names must match (including case).

tag-req-attr

Default: false

If set, specified attributes should be present on the specified tag.

tag-self-close

Default: false

  • "always": Void elements must be self-closed with / (html4 style).
  • "never": Void elements must not be self-closed with / (html5 style).
  • false: No restriction.

The void elements are area, base, br, col, embed, hr, img, input, keygen, link, menuitem, meta, param, source, track, and wbr.

text-ignore-regex

Default: false

A string giving a regular expression, a RegExp object, or false. If set, text matching the given regular expression is ignored by rules which apply to raw text (currently, just spec-char-escape). For example, \[{.*?}\] will exclude text wrapped in [{...}]. Note that such text may still cause the input html to parse incorrectly, which could result in errors in other rules later. To remove such text before parsing, use raw-ignore-regex.

title-max-len

Default: 60

The value is either false or a nonnegative integer. If nonzero, the length of the text in the <title> tag must not exceed the given value.

title-no-dup

If set, the <title> tag must not appear twice in the head.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.