my use-case is the following :
I\'m composing an HTML page by using parts that are valid HTML fragments but not valid pages, like <
If you're not comfortable using HTML features that haven't reached a maturity level of W3C Recommendation, there isn't a standard way of adding to the of a page.
If you're comfortable using less mature features, HTML5.2 appears to be standardizing elements to be allowed anywhere flow content is expected (i.e. the and most of its elements).
If you're already using the [scoped] attribute, stop using the [scoped] attribute, as it was never standardized and is losing browser support.
In HTML4.01 the style element was allowed in the only. Browsers, being diligent about attempting to render what the author wants rather than what the author wrote have respected elements in the despite those pages technically being invalid.
The element continued to be invalid in the
In some working drafts of the HTML5.1 spec the element was to allow for a [scoped] attribute, which would allow the element to be used in flow content (i.e. in the ).
As an example of how that could have been used would be:
Example of using the scoped attribute
this text would be dark red
this text would be black
Support for the scoped feature was added to Firefox in version 21 and added in Chrome behind a flag in version 20. The feature didn't receive enough support, so it was later removed from the HTML5.1 working draft.
Chrome was first to remove the feature in version 36. Firefox has since set the feature to be behind a flag in version 55.
In the July 2017 working draft of the HTML5.2 spec, support was added for the element to be allowed in flow content:
Contexts in which this element can be used:
- Where metadata content is expected.
- In a
element that is a child of aelement.- In the body, where flow content is expected.
Emphasis mine
At the time of writing this addition has remained in the HTML5.2 spec, which is currently at the Candidate Recommendation maturity level.
While this makes using elements in the still somewhat of a risk, this particular change is standardizing something that browsers have supported for many years.