Links & Tag Attributes
Tag Attributes
Try It: View the source of this page and look
for the link to Amazon in the paragraph on the left.
Remember: Not all attributes require a value.
An attribute is just a way of telling the browser something about a tag.
Attributes usually have two parts, the name and
the value. The name is always required, and most
attributes also require a value. A good way to think about tag attributes
is as a question and an
answer. For example, the attribute for the anchor
tag that allows you to set the destination of the link is named
href
(which stands for hypertext reference). So an anchor tag linking
a page to Amazon would look like this:
Remember: Not all attributes require a value.
Attribute Example
... so the question is "What is the hypertext reference?"
and the answer is "http://amazon.com"
<a href="http://amazon.com">Amazon</a>
Try It: Add a link to your page using the
Now that you understand what an attribute is, try putting a link of your own in your
page using the anchor tag. Remember that the name of your attribute should be
href and the
value should be the URL of the page you
want to link to. This can be any page on the web!
<a>
tag and the href attribute.
Remember: Put attributes in the start tag and attribute values in "quotation marks".
Example: You might see:
but you should never see:
(Can you guess what the first example does? Try It!)
There are a couple of rules about attributes you should know. The first is
that if a tag is a container tag, such as the
Example: You might see:
<body
bgcolor="red">
...
</body>
<body>
...
</body bgcolor="red">
<body>
tag, any attributes are always in the
start tag.
Another rule about attributes is that the value, such as red in this example, are always surrounded by quotation marks, like "this". Although some browsers may understand some attribute values even when they are not in quotation marks, the best web authors always use them!