Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it valid for css at-rule to be in style attribute?

Tags:

html

css

Is the following markup valid?

<!DOCTYPE html>
<html>
    <head>
         <title>Test whether at-rules are valid in style attributes</title>
    </head>
    <body style="@import url(style.css);"></body>
</html>

Firefox and Chromium on Linux don't render it, but the W3C validator did not mark it as an error.

like image 839
steve Avatar asked Nov 15 '25 13:11

steve


2 Answers

No.

Only a declaration may be placed inside a style attribute.

From the HTML 4.01 specification:

The syntax of the value of the style attribute is determined by the default style sheet language. For example, for [[CSS2]] inline style, use the declaration block syntax described in section 4.1.8 (without curly brace delimiters).

like image 195
Quentin Avatar answered Nov 17 '25 07:11

Quentin


It is not.

@-rules can't contain rules directly, but only selectors.

  • @import imports a file, but they can't have rules outside selectors.
  • @media can only contain selectors.
  • @font-face doesn't affect elements.

The style attribute is meant for setting rules directly to elements, so clearly the @-rules don't fit to that.

like image 28
PurkkaKoodari Avatar answered Nov 17 '25 07:11

PurkkaKoodari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!