Skip to main content

no-disallowed-attr

Warn if an attribute is defined by the specification but not allowed in this context: the attribute is explicitly marked as not for use on this element (noUse), a conditional attribute's condition doesn't currently hold, or the is attribute is specified on an autonomous custom element.

This rule according to HTML Living Standard. It has settings in @markuplint/html-spec.

Whether the attribute name exists at all is no-unknown-attr's concern; an invalid value on an otherwise-allowed attribute is no-invalid-attr-value's.

❌ Examples of incorrect code for this rule

<a target="_blank">The Anchor</a>

✅ Examples of correct code for this rule

<a href="/" target="_blank">The Anchor</a>
note

This rule doesn't evaluate the element that has the spread attribute in some condition. For example, it disallows setting the target attribute on the a element when it doesn't have the href attribute, but Markuplint can't evaluate this when it doesn't know whether the spread attribute includes the href property.

const Component = (props) => {
return <a target="_blank" {...props}>;
}

Interface

{
"no-disallowed-attr": boolean
}

Options

{
"no-disallowed-attr": {
"options": {
"allowAttrs"?: (string | Attr)[] | Record&lt;string, AttributeType | Pattern&gt;
"ignoreAttrNamePrefix"?: string | string[]
}
}
}
type Attr = {
name: string;
value: AttributeType | Pattern;
}

type Pattern = { pattern: string; };

AttributeType is The type API. Pattern is also part of the type API.

PropertyTypeDefault ValueDescription
allowAttrs(string | Attr)[] | Record<string, AttributeType | Pattern>undefinedSpecify the attribute names to treat as known and allowed here, beyond what the spec defines — this is the same option no-unknown-attr accepts; set it identically on both rules when you extend what an element accepts.
ignoreAttrNamePrefixstring | string[]undefinedSet prefixes to exclude special attributes or directives for the library and template engine that do not exist in the HTML specifications.

Default Severity

error

Details

Setting allowAttrs option

Shares its shape with no-unknown-attr's option of the same name — see that rule for the full description. Set the same allowAttrs on both rules so the two stay in sync.

Setting ignoreAttrNamePrefix option

Shares its shape with no-unknown-attr's option of the same name.