• Donal

    (@donalmacarthur)


    Adding CSS declarations within <style> tags to the page body is generally frowned on, but it’s potentially very useful, e.g. for styling elements added to the page using shortcodes. WordPress itself does this with its [gallery] shortcode.

    I’ve never seen anyone else using this ability and so I’m wondering: are there any downsides? I know it means pages with older doctypes won’t validate, but what I really want to know is: are there any cases where it just won’t work?

    Also, how, if at all, does the HTML5 doctype change things? Are <style> elements in the page body legitimate in HTML5?

    If anyone has any thoughts on this, I’d love to hear them.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’ve never seen anyone else using this ability

    Really? Plugins and themes use it all the time. No real downsides providing you aren’t loading in too much CSS as far as I know.

    Thread Starter Donal

    (@donalmacarthur)

    Thanks esmi, that’s good to know.

    To answer my own second question for anyone who’s interested, it turns out style tags in the page body are valid in HTML5 as long as you use the new ‘scoped’ attribute. W3Schools documents it here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Adding CSS directly to the page body’ is closed to new replies.