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?
The HTML id attribute is used to specify a unique id for an HTML element. You cannot have more than one element with the same id in an HTML document.
Note: Technically, the value for an id attribute may contain any character, except whitespace characters. However, to avoid inadvertent errors, only ASCII letters, digits, '_' , and '-' should be used and the value for an id attribute should start with a letter.
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Applying the same id to multiple elements is invalid HTML and should be avoided. For that purpose we have class attributes, which may be distrbuted everywhere and anywhere. The reason we can only have one id is because it is a fragment identifier that can be hooked with an HREF.
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.
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 --
>
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