Invalidate the use of CSS inline styles in HTML
npm install @hint/hint-no-inline-stylesThis hint checks if the HTML is using inline CSS styles.
The use of inline CSS styles prevent the reuse of the styles anywhere else.
The html markup of the page becomes hard to read for the naked eye. The inline
CSS styles are hard to maintain and does not provide consistency since they are
not stored in a single place. The inline styles are repeated downloaded by the
client on every request since it does not provide you with browser cache
advantage. Inline styles take precedence of external stylesheets, this could
accidentally override styles that you did not intend to overwrite.
This hint checks if the HTML is using inline CSS styles.
Examples of inline CSS styles
It checks that no element has the attribute style.
It also checks that no internal styles is used.
The hint will trigger if any element have the attribute style
``html`
The hint will trigger if you use internal styles, this is disabled by default
`html`
No inline style in the element
`html`
...
...
Hi styles
requireNoStyleElement can be set to true to disallow and require the use ofstyle
no tag.
In the [.hintrc][hintrc] file:
`json`
{
"connector": {...},
"formatters": [...],
"hints": {
"no-inline-styles": [ "warning", {
"requireNoStyleElement": true
}],
...
},
...
}
Install this hint with:
`bash`
npm install @hint/hint-no-inline-styles --save-dev
To use it, activate it via the [.hintrc][hintrc] configuration file:
`json``
{
"connector": {...},
"formatters": [...],
"parsers": [...],
"hints": {
"no-inline-styles": "error",
...
},
...
}
- [Why CSS inline styles are considered harmful for accessibility][why-css-inline-styles-are-considered-harmful-accessibility]
[hintrc]: https://webhint.io/docs/user-guide/configuring-webhint/summary/
[why-css-inline-styles-are-considered-harmful-accessibility]: https://www.nomensa.com/blog/2011/css-inline-styles-and-why-they-are-considered-harmful-accessibility