3 ms·
OK, so this part is new to me: Don't inline CSS attributes Inlining CSS attributes on HTML elements (e.g., <p style=...>) should be avoided where possible, as
by coverband 11y ago
OK, so this part is new to me:
Don't inline CSS attributes
Inlining CSS attributes on HTML elements (e.g., <p style=...>) should be avoided where possible, as this often leads to unnecessary code duplication. Further, inline CSS on HTML elements is blocked by default with Content Security Policy (CSP).
How effective is this, really? If I can inline a CSS class, then I can inject any style on any HTML element even if I can't inline an attribute. Am I missing something here?
- lutusp 11y agoTheir point seems to be that inlining a class name means the class will only be defined once, but the case of an inlined style means the style information must be duplicated for each appearance. The style approach hits all the bad buttons -- the load is larger and slower, and its execution is slowed compared to a single class definition that's referred to multiple times. Also, in the case of a defined class, you only need to change the class definition to change all the instances, rather than chasing down each explicit style instance. The reasoning is only valid if the defined style is used more than once. If the style is unique, the argument doesn't hold up.