Is it ever okay to include inline CSS in plugins?

TL;DR; Enqueue

Using external stylesheet

  • PRO: All your styles are in one spot.
  • PRO: Reduces web page coding.
  • PRO: Easier to maintain the plugin.
  • PRO: Can use hooks to alter location of the file.
  • PRO: Can use hooks to unqueue the file.
  • PRO: Can use minify styles automatically.
  • CON: Might add extra HTTP request (can be overcome).

Using inline styles

  • PRO: Can directly see the style applied.
  • PRO: No extra HTTP requests.
  • CON: Can not use hooks to alter the styles.
  • CON: Can not use hooks to unqueue the styles.
  • CON: Can not minify styles at all.
  • CON: Need !important to override style

Normally I would say: Sure, if you are the only one using it, go ahead and do it inline. But you are talking about a plugin which means the code will be public so aim for extendibility. Right now you only have a few lines of styling:

  • CON: What if that few become more?
  • CON: What if someone extends your plugin?
  • CON: What if someone wants to alter it?
  • CON: What if someone searches for it in css files?
  • CON: What if someone wants to minify it automatically?

Therefore, enqueue. (Preferably Conditionally only if the plugin needs it.)
The same applies to JavaScript. (But that should be included in the footer if possible.)

Leave a Comment