<p>When creating the <code>id</code> attributes for HTML elements, what rules are there for the value?</p>

[{'answer_id': 70586, 'author': 'Peter Hilton', 'author_id': 2670, 'author_profile': 'https://Stackoverflow.com/users/2670', 'pm_score': 8, 'selected': False, 'text': '<p>From the <a href="http://www.w3.org/TR/html4/types.html#type-id" rel="noreferrer">HTML 4 specification</a>:</p>\n\n<blockquote>\n  <p>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 (".").</p>\n</blockquote>\n\n<p>A common mistake is to use an ID that starts with a digit.</p>\n'}, {'answer_id': 70599, 'author': 'Mr Shark', 'author_id': 6093, 'author_profile': 'https://Stackoverflow.com/users/6093', 'pm_score': 6, 'selected': False, 'text': '<p>Strictly it should match</p>\n<pre><code>[A-Za-z][-A-Za-z0-9_:.]*\n</code></pre>\n<p>But <a href="https://en.wikipedia.org/wiki/JQuery" rel="nofollow noreferrer">jQuery</a> seems to have problems with colons, so it might be better to avoid them.</p>\n'}, {'answer_id': 70607, 'author': 'Steve Morgan', 'author_id': 5806, 'author_profile': 'https://Stackoverflow.com/users/5806', 'pm_score': 4, 'selected': False, 'text': '<p>From the HTML 4 specification...</p>\n<p>The 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 (&quot;-&quot;), underscores (&quot;_&quot;), colons (&quot;:&quot;), and periods (&quot;.&quot;).</p>\n'}, {'answer_id': 70894, 'author': 'pdc', 'author_id': 8925, 'author_profile': 'https://Stackoverflow.com/users/8925', 'pm_score': 5, 'selected': False, 'text': '<p>In practice many sites use <code>id</code> attributes starting with numbers, even though this is technically not valid HTML.</p>\n\n<p>The <a href="http://www.w3.org/html/wg/html5/#id" rel="noreferrer">HTML 5 draft specification</a> loosens up the rules for the <code>id</code> and <code>name</code> attributes: they are now just opaque strings which cannot contain spaces.</p>\n'}, {'answer_id': 71734, 'author': 'Vordreller', 'author_id': 11795, 'author_profile': 'https://Stackoverflow.com/users/11795', 'pm_score': 4, 'selected': False, 'text': "<p>Also, never forget that an ID is unique. Once used, the ID value may not appear again anywhere in the document.</p>\n\n<p>You may have many ID's, but all must have a unique value.</p>\n\n<p>On the other hand, there is the class-element. Just like ID, it can appear many times, but the value may be used over and over again.</p>\n"}, {'answer_id': 72577, 'author': 'Michael Thompson', 'author_id': 12276, 'author_profile': 'https://Stackoverflow.com/users/12276', 'pm_score': 7, 'selected': False, 'text': '<p>You can technically use colons and periods in id/name attributes, but I would strongly suggest avoiding both.</p>\n\n<p>In CSS (and several JavaScript libraries like jQuery), both the period and the colon have special meaning and you will run into problems if you\'re not careful. Periods are class selectors and colons are pseudo-selectors (eg., ":hover" for an element when the mouse is over it).</p>\n\n<p>If you give an element the id "my.cool:thing", your CSS selector will look like this:</p>\n\n<pre><code>#my.cool:thing { ... /* some rules */ ... }\n</code></pre>\n\n<p>Which is really saying, "the element with an id of \'my\', a class of \'cool\' and the \'thing\' pseudo-selector" in CSS-speak.</p>\n\n<p>Stick to A-Z of any case, numbers, underscores and hyphens. And as said above, make sure your ids are unique.</p>\n\n<p>That should be your first concern.</p>\n'}, {'answer_id': 79022, 'author': 'dgvid', 'author_id': 9897, 'author_profile': 'https://Stackoverflow.com/users/9897', 'pm_score': 12, 'selected': True, 'text': '<p>For <a href="http://www.w3.org/TR/html4/types.html#type-id" rel="noreferrer">HTML 4</a>, the answer is technically:</p>\n\n<blockquote>\n  <p>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 (".").</p>\n</blockquote>\n\n<p><a href="https://www.w3.org/TR/html5/dom.html#the-id-attribute" rel="noreferrer">HTML 5</a> is even more permissive, saying only that an id must contain at least one character and may not contain any space characters.</p>\n\n<p>The id attribute is case sensitive in <a href="https://www.w3.org/TR/xhtml1/diffs.html#h-4.2" rel="noreferrer">XHTML</a>.</p>\n\n<p>As a purely practical matter, you may want to avoid certain characters. Periods, colons and \'#\' have special meaning in CSS selectors, so you will have to escape those characters using a <a href="http://www.w3.org/TR/CSS2/syndata.html#value-def-identifier" rel="noreferrer">backslash in CSS</a> or a double backslash in a <a href="http://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/" rel="noreferrer">selector string passed to jQuery</a>. Think about how often you will have to escape a character in your stylesheets or code before you go crazy with periods and colons in ids.</p>\n\n<p>For example, the HTML declaration <code>&lt;div id="first.name"&gt;&lt;/div&gt;</code> is valid. You can select that element in CSS as <code>#first\\.name</code> and in jQuery like so: <code>$(\'#first\\\\.name\').</code> But if you forget the backslash, <code>$(\'#first.name\')</code>, you will have a perfectly valid selector looking for an element with id <code>first</code> and also having class <code>name</code>. This is a bug that is easy to overlook. You might be happier in the long run choosing the id <code>first-name</code> (a hyphen rather than a period), instead.</p>\n\n<p>You can simplify your development tasks by strictly sticking to a naming convention. For example, if you limit yourself entirely to lower-case characters and always separate words with either hyphens or underscores (but not both, pick one and never use the other), then you have an easy-to-remember pattern. You will never wonder "was it <code>firstName</code> or <code>FirstName</code>?" because you will always know that you should type <code>first_name</code>. Prefer camel case? Then limit yourself to that, no hyphens or underscores, and always, consistently use either upper-case or lower-case for the first character, don\'t mix them.</p>\n\n<hr>\n\n<p>A now very obscure problem was that at least one browser, Netscape 6, <a href="https://developer.mozilla.org/en-US/docs/Case_Sensitivity_in_class_and_id_Names" rel="noreferrer">incorrectly treated id attribute values as case-sensitive</a>. That meant that if you had typed <code>id="firstName"</code> in your HTML (lower-case \'f\') and <code>#FirstName { color: red }</code> in your CSS (upper-case \'F\'), that buggy browser would have failed to set the element\'s color to red. At the time of this edit, April 2015, I hope you aren\'t being asked to support Netscape 6. Consider this a historical footnote.</p>\n'}, {'answer_id': 431712, 'author': 'Álvaro González', 'author_id': 13508, 'author_profile': 'https://Stackoverflow.com/users/13508', 'pm_score': 6, 'selected': False, 'text': '<p>jQuery <strong>does</strong> handle any valid ID name. You just need to escape metacharacters (i.e., dots, semicolons, square brackets...). It\'s like saying that JavaScript has a problem with quotes only because you can\'t write</p>\n\n<pre><code>var name = \'O\'Hara\';\n</code></pre>\n\n<p><a href="http://docs.jquery.com/Selectors" rel="noreferrer">Selectors in jQuery API (see bottom note)</a></p>\n'}, {'answer_id': 776500, 'author': 'lstg', 'author_id': 94256, 'author_profile': 'https://Stackoverflow.com/users/94256', 'pm_score': 4, 'selected': False, 'text': '<p>It appears that, although colons (:) and periods (.) are valid in the HTML specification, they are invalid as id selectors in <a href="http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier" rel="nofollow noreferrer">CSS</a>, so they are probably best avoided if you intend to use them for that purpose.</p>\n'}, {'answer_id': 3193773, 'author': 'blacksun1', 'author_id': 385410, 'author_profile': 'https://Stackoverflow.com/users/385410', 'pm_score': 5, 'selected': False, 'text': '<p>Hyphens, underscores, periods, colons, numbers and letters are all valid for use with CSS and jQuery. The following should work, but it must be unique throughout the page and also must start with a letter [A-Za-z].</p>\n<p>Working with colons and periods needs a bit more work, but you can do it as the following example shows.</p>\n<pre><code>&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;Cake&lt;/title&gt;\n&lt;style type=&quot;text/css&quot;&gt;\n    #i\\.Really\\.Like\\.Cake {\n        color: green;\n    }\n    #i\\:Really\\:Like\\:Cake {\n        color: blue;\n    }\n&lt;/style&gt;\n&lt;/head&gt;\n&lt;body&gt;\n    &lt;div id=&quot;i.Really.Like.Cake&quot;&gt;Cake&lt;/div&gt;\n    &lt;div id=&quot;testResultPeriod&quot;&gt;&lt;/div&gt;\n\n    &lt;div id=&quot;i:Really:Like:Cake&quot;&gt;Cake&lt;/div&gt;\n    &lt;div id=&quot;testResultColon&quot;&gt;&lt;/div&gt;\n    &lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;\n    &lt;script type=&quot;text/javascript&quot;&gt;\n        $(function() {\n            var testPeriod = $(&quot;#i\\\\.Really\\\\.Like\\\\.Cake&quot;);\n            $(&quot;#testResultPeriod&quot;).html(&quot;found &quot; + testPeriod.length + &quot; result.&quot;);\n\n            var testColon = $(&quot;#i\\\\:Really\\\\:Like\\\\:Cake&quot;);\n            $(&quot;#testResultColon&quot;).html(&quot;found &quot; + testColon.length + &quot; result.&quot;);\n        });\n    &lt;/script&gt;\n&lt;/body&gt;\n&lt;/html&gt;\n</code></pre>\n'}, {'answer_id': 12546546, 'author': 'Shashank N. Pandey', 'author_id': 1676940, 'author_profile': 'https://Stackoverflow.com/users/1676940', 'pm_score': -1, 'selected': False, 'text': "<p>alphabets → caps &amp; small</p>\n<p>digits → 0-9</p>\n<p>special characters → ':', '-', '_', '.'</p>\n<p>The format should be either starting from '.' or an alphabet, followed by either of the special characters of more alphabets or numbers. The value of the id field must not end at an '_'.</p>\n<p>Also, spaces are not allowed, if provided, they are treated as different values, which is not valid in case of the id attributes.</p>\n"}, {'answer_id': 14394034, 'author': 'Zaheer Ahmed', 'author_id': 821057, 'author_profile': 'https://Stackoverflow.com/users/821057', 'pm_score': 6, 'selected': False, 'text': '<h2>HTML5:</h2>\n<p>It gets rid of the additional restrictions on the <em>id</em> attribute (<a href="http://www.w3.org/TR/2011/WD-html5-20110525/elements.html#the-id-attribute" rel="noreferrer">see here</a>). The only requirements left (apart from being unique in the document) are:</p>\n<ol>\n<li>the value must contain at least one character (can’t be empty)</li>\n<li>it can’t contain any space characters.</li>\n</ol>\n<hr />\n<h2>Pre-HTML5:</h2>\n<p>ID should match:</p>\n<pre><code>[A-Za-z][-A-Za-z0-9_:.]*\n</code></pre>\n<ol>\n<li>Must <em>start</em> with A-Z or a-z characters</li>\n<li>May contain <code>-</code> (hyphen), <code>_</code> (underscore), <code>:</code> (colon) and <code>.</code> (period)</li>\n</ol>\n<p>But one should avoid <code>:</code> and <code>.</code> because:</p>\n<p>For example, an ID could be labelled &quot;a.b:c&quot; and referenced in the style sheet as #a.b:c, but as well as being the id for the element, it could mean id &quot;a&quot;, class &quot;b&quot;, pseudo-selector &quot;c&quot;. It is best to avoid the confusion and stay away from using <code>.</code> and <code>:</code> altogether.</p>\n'}, {'answer_id': 16331721, 'author': 'Web Designer cum Promoter', 'author_id': 1012591, 'author_profile': 'https://Stackoverflow.com/users/1012591', 'pm_score': 3, 'selected': False, 'text': '<ol>\n<li>IDs are best suited for naming parts of your layout, so you should not give the same name for ID and class</li>\n<li>ID allows alphanumeric and special characters</li>\n<li>but avoid using the <code># : . * !</code> symbols</li>\n<li>spaces are not allowed</li>\n<li>not started with numbers or a hyphen followed by a digit</li>\n<li>case sensitive</li>\n<li>using ID selectors is faster than using class selectors</li>\n<li>use hyphen &quot;-&quot; (underscore &quot;_&quot; can also be used, but it is not good for <a href="https://en.wikipedia.org/wiki/Search_engine_optimization" rel="nofollow noreferrer">SEO</a>) for long CSS class or Id rule names</li>\n<li>If a rule has an ID selector as its key selector, don’t add the tag name to the rule. Since IDs are unique, adding a tag name would slow down the matching process needlessly.</li>\n<li>In HTML5, the id attribute can be used on any HTML element and In HTML 4.01, the id attribute cannot be used with: <code>&lt;base&gt;, &lt;head&gt;, &lt;html&gt;, &lt;meta&gt;, &lt;param&gt;, &lt;script&gt;, &lt;style&gt;, and &lt;title&gt;.</code></li>\n</ol>\n'}, {'answer_id': 18355561, 'author': 'Kanishka Panamaldeniya', 'author_id': 733287, 'author_profile': 'https://Stackoverflow.com/users/733287', 'pm_score': 4, 'selected': False, 'text': '<p>For <a href="https://en.wikipedia.org/wiki/HTML5" rel="nofollow noreferrer">HTML5</a>:</p>\n<blockquote>\n<p>The value must be unique amongst all the IDs in the element’s home\nsubtree and must contain at least one character. The value must not\ncontain any space characters.</p>\n</blockquote>\n<p>At least one character, no spaces.</p>\n<p>This opens the door for valid use cases such as using accented characters. It also gives us plenty of more ammo to shoot ourselves in the foot with, since you can now use <em>id</em> values that will cause problems with both CSS and JavaScript unless you’re really careful.</p>\n'}, {'answer_id': 18453687, 'author': 'Sergio', 'author_id': 2256325, 'author_profile': 'https://Stackoverflow.com/users/2256325', 'pm_score': 5, 'selected': False, 'text': '<h2>HTML5</h2>\n<p>Keeping in mind that ID must be unique, i.e., there must not be multiple elements in a document that have the same id value.</p>\n<p>The rules about ID content in HTML5 are (apart from being unique):</p>\n<blockquote>\n<p>This attribute\'s value must not contain white spaces. [...]\nThough this restriction has been lifted in HTML 5, an ID should start with a letter for compatibility.</p>\n</blockquote>\n<p>This is the <strong>W3</strong> spec about ID (from MDN):</p>\n<blockquote>\n<p>Any string, with the following restrictions:</p>\n<ul>\n<li>must be at least one character long</li>\n<li>must not contain any space characters</li>\n</ul>\n<p>Previous versions of HTML placed greater restrictions on the content of ID values (for example, they did not permit ID values to begin with a number).</p>\n</blockquote>\n<h2>More information:</h2>\n<ul>\n<li><a href="http://www.w3.org/TR/html-markup/global-attributes.html#common.attrs.id" rel="nofollow noreferrer"><strong>W3</strong></a> - global attributes (<code>id</code>)</li>\n<li><a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes#id" rel="nofollow noreferrer"><strong>MDN</strong></a> attribute (<code>id</code>)</li>\n</ul>\n'}, {'answer_id': 19963415, 'author': 'Anthony', 'author_id': 1678151, 'author_profile': 'https://Stackoverflow.com/users/1678151', 'pm_score': 4, 'selected': False, 'text': "<p>To reference an id with a period in it, you need to use a backslash. I am not sure if it's the same for hyphens or underscores.</p>\n<p>For example:</p>\n<h3>HTML</h3>\n<pre><code>&lt;div id=&quot;maintenance.instrumentNumber&quot;&gt;############0218&lt;/div&gt;\n</code></pre>\n<p>CSS</p>\n<pre><code>#maintenance\\.instrumentNumber{word-wrap:break-word;}\n</code></pre>\n"}, {'answer_id': 31773673, 'author': 'Michael Benjamin', 'author_id': 3597276, 'author_profile': 'https://Stackoverflow.com/users/3597276', 'pm_score': 6, 'selected': False, 'text': '<h2>HTML5: Permitted Values for ID &amp; Class Attributes</h2>\n\n<p>As of HTML5, the only restrictions on the value of an ID are:</p>\n\n<ol>\n<li>must be unique in the document</li>\n<li>must not contain any space characters</li>\n<li>must contain at least one character</li>\n</ol>\n\n<p>Similar rules apply to classes (except for the uniqueness, of course).</p>\n\n<p>So the value can be all digits, just one digit, just punctuation characters, include special characters, whatever. Just no whitespace. This is very different from HTML4.</p>\n\n<p>In HTML 4, ID values must begin with a letter, which can then be followed only by letters, digits, hyphens, underscores, colons and periods.</p>\n\n<p>In HTML5 these are valid:</p>\n\n<pre><code>&lt;div id="999"&gt; ... &lt;/div&gt;\n&lt;div id="#%LV-||"&gt; ... &lt;/div&gt;\n&lt;div id="____V"&gt; ... &lt;/div&gt;\n&lt;div id="⌘⌥"&gt; ... &lt;/div&gt;\n&lt;div id="♥"&gt; ... &lt;/div&gt;\n&lt;div id="{}"&gt; ... &lt;/div&gt;\n&lt;div id="©"&gt; ... &lt;/div&gt;\n&lt;div id="♤₩¤☆€~¥"&gt; ... &lt;/div&gt;\n</code></pre>\n\n<p>Just bear in mind that using numbers, punctuation or special characters in the value of an ID may cause trouble in other contexts (e.g., CSS, JavaScript, regex).</p>\n\n<p>For example, the following ID is valid in HTML5:</p>\n\n<pre><code>&lt;div id="9lions"&gt; ... &lt;/div&gt;\n</code></pre>\n\n<p><strong><em>However, it is invalid in CSS:</em></strong></p>\n\n<p>From the CSS2.1 spec:</p>\n\n<blockquote>\n  <p><a href="https://www.w3.org/TR/CSS21/syndata.html#characters" rel="noreferrer"><strong>4.1.3 Characters and case</strong></a></p>\n  \n  <p>In CSS, <em>identifiers</em> (including element names, classes, and IDs in\n  selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646\n  characters U+00A0 and higher, plus the hyphen (-) and the underscore\n  (_); <strong><em>they cannot start with a digit, two hyphens, or a hyphen\n  followed by a digit</em></strong>.</p>\n</blockquote>\n\n<p>In most cases you may be able to escape characters in contexts where they have restrictions or special meaning.</p>\n\n<hr>\n\n<p><strong>W3C References</strong></p>\n\n<p>HTML5</p>\n\n<blockquote>\n  <p><a href="http://www.w3.org/TR/html5/dom.html#the-id-attribute" rel="noreferrer"><strong>3.2.5.1 The <code>id</code>\n  attribute</strong></a></p>\n  \n  <p>The <code>id</code> attribute specifies its element\'s unique identifier (ID). </p>\n  \n  <p>The value must be unique amongst all the IDs in the element\'s home\n  subtree and must contain at least one character. The value must not\n  contain any space characters.</p>\n  \n  <p>Note: There are no other restrictions on what form an ID can take; in\n  particular, IDs can consist of just digits, start with a digit, start\n  with an underscore, consist of just punctuation, etc.</p>\n  \n  <p><a href="http://www.w3.org/TR/html5/dom.html#classes" rel="noreferrer"><strong>3.2.5.7 The <code>class</code>\n  attribute</strong></a></p>\n  \n  <p>The attribute, if specified, must have a value that is a set of\n  space-separated tokens representing the various classes that the\n  element belongs to.</p>\n  \n  <p>The classes that an HTML element has assigned to it consists of all\n  the classes returned when the value of the class attribute is split on\n  spaces. (Duplicates are ignored.)</p>\n  \n  <p>There are no additional restrictions on the tokens authors can use in\n  the class attribute, but authors are encouraged to use values that\n  describe the nature of the content, rather than values that describe\n  the desired presentation of the content.</p>\n</blockquote>\n'}, {'answer_id': 38396827, 'author': 'Bhavin Solanki', 'author_id': 3270866, 'author_profile': 'https://Stackoverflow.com/users/3270866', 'pm_score': 4, 'selected': False, 'text': "<p>A unique identifier for the element.</p>\n\n<p>There must not be multiple elements in a document that have the same id value.</p>\n\n<p>Any string, with the following restrictions:</p>\n\n<ol>\n<li>must be at least one character long</li>\n<li><p>must not contain any space characters:</p>\n\n<ul>\n<li>U+0020 SPACE</li>\n<li>U+0009 CHARACTER TABULATION (tab)</li>\n<li>U+000A LINE FEED (LF)</li>\n<li>U+000C FORM FEED (FF)</li>\n<li>U+000D CARRIAGE RETURN (CR)</li>\n</ul></li>\n</ol>\n\n<p>Using characters except <code>ASCII letters and digits, '_', '-' and '.'</code> may cause compatibility problems, as they weren't allowed in <code>HTML 4</code>. Though this restriction has been lifted in <code>HTML 5</code>, an ID should start with a letter for compatibility.</p>\n"}, {'answer_id': 40563537, 'author': 'Tazwar Utshas', 'author_id': 4464547, 'author_profile': 'https://Stackoverflow.com/users/4464547', 'pm_score': 3, 'selected': False, 'text': '<p>Any <strong>alpha-numeric value</strong>,&quot;<strong>-</strong>&quot;, and &quot;<strong>_</strong>&quot; are valid. But, you should <em>start the id name</em> with any character between <strong>A-Z</strong> or <strong>a-z</strong>.</p>\n'}, {'answer_id': 43861092, 'author': 'Joel Wembo', 'author_id': 6437920, 'author_profile': 'https://Stackoverflow.com/users/6437920', 'pm_score': 3, 'selected': False, 'text': '<p>No spaces, and it must begin with at least a character from a to z and 0 to 9.</p>\n'}, {'answer_id': 56597185, 'author': 'Dev pokhariya', 'author_id': 7179457, 'author_profile': 'https://Stackoverflow.com/users/7179457', 'pm_score': 3, 'selected': False, 'text': "<p>In HTML</p>\n<p><strong>ID</strong> should start with <strong>{A-Z}</strong> or <strong>{a-z}</strong>. You can add <strong>digits, periods, hyphens, underscores, and colons.</strong></p>\n<p>For example:</p>\n<pre><code>&lt;span id=&quot;testID2&quot;&gt;&lt;/span&gt;\n&lt;span id=&quot;test-ID2&quot;&gt;&lt;/span&gt;\n&lt;span id=&quot;test_ID2&quot;&gt;&lt;/span&gt;\n&lt;span id=&quot;test:ID2&quot;&gt;&lt;/span&gt;\n&lt;span id=&quot;test.ID2&quot;&gt;&lt;/span&gt;\n</code></pre>\n<p>But even though you can make ID with colons (:) or period (<code>.</code>). It is hard for <strong>CSS</strong> to use these IDs as a selector. Mainly when you want to use pseudo elements (<code>:before</code> and <code>:after</code>).</p>\n<p>Also in JavaScript it is hard to select these ID's.\nSo you should use first four ID's as the preferred way by many developers around and if it's necessary then you can use the last two also.</p>\n"}, {'answer_id': 56920453, 'author': 'Jyotirmoy Bhattacharyya', 'author_id': 9342086, 'author_profile': 'https://Stackoverflow.com/users/9342086', 'pm_score': 3, 'selected': False, 'text': '<p>Walues can be: [a-z], [A-Z], [0-9], [* _ : -]</p>\n<p>It is used for HTML5...</p>\n<p>We can add id with any tag.</p>\n'}, {'answer_id': 57837637, 'author': 'NVRM', 'author_id': 2494754, 'author_profile': 'https://Stackoverflow.com/users/2494754', 'pm_score': 3, 'selected': False, 'text': '<p>Since <em>ES2015</em> we can as well use <em>almost</em> all <strong>Unicode characters</strong> for ID\'s, if the document character set is set to UTF-8.</p>\n<p>Test out here: <a href="https://mothereff.in/js-variables" rel="nofollow noreferrer">https://mothereff.in/js-variables</a></p>\n<p><a href="https://i.stack.imgur.com/E4FWL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4FWL.png" alt="Enter image description here" /></a></p>\n<p>Read about it: <em><a href="https://mathiasbynens.be/notes/javascript-identifiers-es6" rel="nofollow noreferrer">Valid JavaScript variable names in ES2015</a></em></p>\n<blockquote>\n<p>In ES2015, identifiers must start with $, _, or any symbol with the\nUnicode derived core property ID_Start.</p>\n<p>The rest of the identifier can contain $, _, U+200C zero width\nnon-joiner, U+200D zero width joiner, or any symbol with the Unicode\nderived core property ID_Continue.</p>\n</blockquote>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>const target = document.querySelector("div").id\n\nconsole.log("Div id:", target )\n\ndocument.getElementById(target).style.background = "chartreuse"</code></pre>\r\n<pre class="snippet-code-css lang-css prettyprint-override"><code>div {\n  border: 5px blue solid;\n  width: 100%;\n  height: 200px\n}</code></pre>\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="H̹̙̦̮͉̩̗̗ͧ̇̏̊̾Eͨ͆͒̆ͮ̃͏̷̮̣̫̤̣Cͯ̂͐͏̨̛͔̦̟͈̻O̜͎͍͙͚̬̝̣̽ͮ͐͗̀ͤ̍̀͢M̴̡̲̭͍͇̼̟̯̦̉̒͠Ḛ̛̙̞̪̗ͥͤͩ̾͑̔͐ͅṮ̴̷̷̗̼͍̿̿̓̽͐H̙̙̔̄͜"&gt;&lt;/div&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n<hr />\n<p>Should you use it? Probably not a good idea!</p>\n<p>Read about it: <em><a href="https://stackoverflow.com/questions/11945216/javascript-syntax-error-missing-after-function-body/52799593#52799593">JavaScript: &quot;Syntax error missing } after function body&quot;</a></em></p>\n'}, {'answer_id': 66589027, 'author': "Danny '365CSI' Engelman", 'author_id': 2520800, 'author_profile': 'https://Stackoverflow.com/users/2520800', 'pm_score': 1, 'selected': False, 'text': '<p>Help, my Javascript is broken!</p>\n<p>Everyone says IDs can\'t be duplicates.</p>\n<p>Best tried in every browser but FireFox</p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="ONE"&gt;&lt;/div&gt;\n&lt;div id="ONE"&gt;&lt;/div&gt;\n&lt;div id="ONE"&gt;&lt;/div&gt;\n&lt;script&gt;\n  document.body.append( document.querySelectorAll("#ONE").length , \' DIVs!\')\n  document.body.append( \' in a \', typeof ONE )\n  console.log( ONE ); // a global var !!\n&lt;/script&gt;</code></pre>\r\n</div>\r\n</div>\r\n</p>\n<h1><strong>Explanation</strong></h1>\n<p><img src="https://upload.wikimedia.org/wikipedia/commons/2/24/Browser_Wars_%28en%29.svg" alt="" /></p>\n<p>After the turn of the century Microsoft had 90% Browser Market share,</p>\n<p>and implemented Browser behaviours that where never standardized:</p>\n<p><strong>1. create global variables for every ID</strong></p>\n<p><strong>2. create an Array for <strong>duplicate</strong> IDs</strong></p>\n<p><strong>All</strong> later Browser vendors copied this behaviour, otherwise their browser wouldn\'t support older sites.</p>\n<p>Somewhere around 2015 Mozilla removed 2. from FireFox and 1. still works.</p>\n<p>All other browsers still do 1. and 2.</p>\n<p>I use it every day because typing <code>ONE</code> instead of <code>document.querySelector(&quot;#ONE&quot;)</code> helps me prototype faster; I do not use it in production.</p>\n'}, {'answer_id': 66898851, 'author': 'baijugoradia', 'author_id': 8696792, 'author_profile': 'https://Stackoverflow.com/users/8696792', 'pm_score': 0, 'selected': False, 'text': "<p><em><strong>Html ID</strong></em></p>\n<p>The id attribute specifies its element's unique identifier (ID).</p>\n<p>There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.</p>\n<p>An element's unique identifier can be used for a variety of purposes, most notably as a way to link to specific parts of a document using fragments, as a way to target an element when scripting, and as a way to style a specific element from CSS.</p>\n"}, {'answer_id': 66937072, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<ol>\n<li>Uppercase and lowercase alphabets works</li>\n<li>'_' and '-' works, too</li>\n<li>Numbers works</li>\n<li>Colons (,) and period (.) seems to work</li>\n<li>Interestingly, emojis work</li>\n</ol>\n"}]
['https://Stackoverflow.com/questions/70579', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6093/']