Can I skip attribute “type” in “style” tag in HTML5? [duplicate]

若如初见. 提交于 2019-12-08 14:35:55

问题


According to W3Schools, I can skip attribute type for tag script in HTML5.

Evidence:

Differences Between HTML 4.01 and HTML5

The "type" attribute is required in HTML 4, but optional in HTML5.

Can I do exactly the same with style tag? I was unable to find similar note. It only says

type text/css Specifies the media type of the tag

but no info about omitting it. I don't care about IE, Edge or that sort of crap from Microsoft. I would like to write as less unnecessary code as possible. Ideally I would like to use just:

<style>.foo { color: red; }</style>

回答1:


According to the documentation:

type

This attribute defines the styling language as a MIME type (charset should not be specified). This attribute is optional and default to text/css if it's missing.

Also comparing html 4.01 and html 5:

html 4.01

type = content-type [CI]

This attribute specifies the style sheet language of the element's contents and overrides the default style sheet language. The style sheet language is specified as a content type (e.g., "text/css"). Authors must supply a value for this attribute; there is no default value for this attribute.

html 4.01 - The style element w3c

html 5

The type attribute gives the styling language. If the attribute is present, its value must be a valid MIME type that designates a styling language. The charset parameter must not be specified. The default value for the type attribute, which is used if the attribute is absent, is "text/css".

html 5 - The style element w3c




回答2:


Yes, you can, according to the specification:

The type attribute gives the styling language. If the attribute is present, its value must be a valid MIME type that designates a styling language. The charset parameter must not be specified. The default value for the type attribute, which is used if the attribute is absent, is "text/css". [RFC2318]

The default value already is text/css.



来源:https://stackoverflow.com/questions/33210842/can-i-skip-attribute-type-in-style-tag-in-html5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!