Pub Pixel Avatar Image

The Id Attribute Unrestricted And Uncensored In HTML5

Published:

Rate Article (Sign in and be the first to rate this article.)

Article Details

Views: 610

First Published:

Word Count: 604

Edition: 1

What did HTML5 do to the id attribute? It made it better. How you say, first let me explain to you what the id attribute is intended to do. The id attribute gives the HTML element its placed in a unique identifier.

In HTML5 the id attribute can be placed in any HTML element unlike in previous versions of HTML where the id attribute could not be placed in the <base>, <head>, <html>, <meta>, <script>, <style> and <title> elements. Now since HTML5 now allows the id attribute to be placed in any HTML element the id attribute is now considered to be a global attribute, you can learn more about global attributes and how to use them in an earlier tutorial that was published called "What The Heck Are Global Attributes In HTML?".

The value of the id attribute must be at least one character long and must not contain any space characters for example, a space, tab, carriage return, form feed or line feed. In HTML5 the id attribute can begin with a number unlike in previous versions of HTML that required the value to begin with a letter ([A-Za-z]) and then it may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods ("."). The id attribute may also contain any escaped characters, for example, <p id="&#9763;">...</p> or any Unicode characters, for example, <p id="☣">...</p> as its value. Now in HTML the id attributes value is case-sensitive meaning that <p id="foo">...</p> is different from <p id="FOO">...</p> in HTML, so basically the id attributes value can contain lowercase or uppercase letters or a combination of both in HTML, but it's considered good practice to keep all of your HTML mark-up lowercase when possible. Even though the id attributes value can start with any character its best to start the id attributes value with a letter ([A-Za-z]) and then it may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), periods (".") or any other type of characters in-order to keep inline with the w3.org CSS 2.1 specifications and to have your CSS code validate, if applying CSS styles to the id attributes value. Its important to remember that there can not be multiple elements in the same web page with the same id value for the id attribute.

The id attribute is usually used by CSS as a style sheet selector, or for linking to named anchors. The id attribute can also be used by scripts like JavaScript. These are just some of the ways an id attribute can be used.

Here is how to code the id attribute for HTML5 in the example below.


<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Welcome To HTML5</title>
</head>
<body>
  
 <p id="blah">Some random text.</p>  

</body>
</html>

And here is how to code the id attribute in XHTML5 in the example below.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
 <meta charset="UTF-8" />
 <title>Welcome To XHTML5</title>
</head>
<body>

 <p id="blah">Some random text.</p>  

</body>
</html>

Article Tags

Tag Article (Sign in if you want to tag this article.)

Share This Article

Send To Facebook Link

Tweet This Link

Send To LinkedIn Link

Send To StumbleUpon Link

Digg This Link

Send To Google Plus One Share Link

Send To Reddit Link

Send To Tumblr Link

Send To Delicious Link

Send To FriendFeed Link

Send To Diigo Link

Email Link

AddThis Link

0 Comments

Leave Comment (Sign in and be the first to comment on this article.)

Important

This site cannot guarantee the accuracy of articles, comments, answers and other types of content or media submitted by members or anonymous users and guests, and we recommend that you use common sense when following any advice or information found on this site. Read our full Content Disclaimer Agreement for further information.