Web Design

(Nancy Kaufman) #1

41


CHAPTER

Getting Started with HTML 2


What is the ID attribute?
The ID attribute can be used to identify a particular
element. In addition to becoming the target of
links, IDs can also be used in CSS and JavaScript.
You can add an ID attribute to almost any tag in
your HTML document.

Are there restrictions on what I can use for an ID?
The value of the ID attribute cannot contain spaces,
but almost more important is that it must be unique
on a page. You cannot have two elements share the
same ID on the same page; if you do, you get
unpredictable results in various browsers. The ID
value is also case-sensitive, so be sure to stay
consistent in how you capitalize it.

4 Scroll in the document to the
point to which you want the
link to go when clicked.
5 In the existing tag at that
point, type id=”?”,
replacing? with the same
identifier you used in Step 2.
Note: The identifier is case-
sensitive, so be sure it matches
exactly.


Note: If no tag exists at the
point to which you want to link,
you can use ,
again replacing? with the
identifier from Step 2. Be sure to
add a closing
tag.


● When viewed in a browser, the
link is blue and underlined.
Click it to have the browser
scroll to the other point in the
document.

4 5


TIPS

Free download pdf