In HTML 4 and XHTML 1, you can't assign a class to the <head>
element. However, in XHTML 1.0 you can give it an ID. In HTML5 it seems you can give it a class. I am curious, why you would want to?
class
is one of what are now called global attributes (along with global events). They'll have to apply to every single element in the DOM, regardless of its nature.
I believe it's related to the API. The spec defines every DOM HTML element to inherit from a base interface called HTMLElement
that defines the aforementioned global attributes and events. Namely:
interface HTMLElement : Element {
// ...
// metadata attributes
attribute DOMString id;
attribute DOMString title;
attribute DOMString lang;
attribute DOMString dir;
attribute DOMString className;
readonly attribute DOMTokenList classList;
readonly attribute DOMStringMap dataset;
With that said, the editor(s) of the spec did make the following note at the end of the list of global attributes/events:
Note: While these attributes apply to all elements, they are not useful on all elements. For example, only media elements will ever receive a
volumechange
event fired by the user agent.
So I suppose they don't expect you to, but they can neither think of a reason to allow it or not to allow it. It's just part of the API (i.e. an HTMLHeadElement
is an HTMLElement
anyway).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With