Reputation: 116283
I'm reading this basic tutorial on canvas
elements. The (almost)
in the following sentence caught my eye:
The id attribute isn't specific to the element but is one of the default HTML attributes which can be applied to (almost) every HTML element
Which html elements cannot accept an id?
Upvotes: 14
Views: 285
Reputation: 54729
In HTML5, the id
attribute is a global attribute and can be specified on any element.
If you look through the Document Type Declaration for HTML4, you can find the elements which do not have %attrs;
defined in their attribute list to indicate they do not support the id
attribute. Those included are near the bottom in the "Document Head" section: HEAD
, TITLE
, BASE
, META
, STYLE
, SCRIPT
, and HTML
.
Note that although the PARAM
element does not include the %attrs;
declaration in its attribute list, it does explicitly allow the id
attribute itself in that list.
<!ATTLIST PARAM
id ID #IMPLIED -- document-wide unique id --
name CDATA #REQUIRED -- property name --
value CDATA #IMPLIED -- property value --
valuetype (DATA|REF|OBJECT) DATA -- How to interpret value --
type %ContentType; #IMPLIED -- content type for value
when valuetype=ref --
>
Upvotes: 13
Reputation: 382150
From w3schools (yes, I know...) :
Note: The id attribute is not valid in:
<base>
,<head>
,<html>
,<meta>
,<param>
,<script>
,<style>
, and<title>
.
Note that this is only valid for HTML4 but that explains the "almost" of the tutorial.
As others have pointed out, HTML5 accepts id on all elements.
Upvotes: 14
Reputation: 201588
It’s a bit surprising that they say this in the context of the canvas
element, which is an HTML5 element. In HTML5, the id
attribute is allowed for any element without exception. Earlier versions of HTML impose various limitations. HTML 4.01 excludes base
, head
, html
, meta
, script
, style
, and title
, but XHTML 1.01 removes this restriction.
Upvotes: 3