Attributes

Attributes modify the behavior of a tag. Attributes allow you to change sizes, colors, specify link locations, and much more.

Attribute Components

Attributes have two main components:

<tagname attribute1="value1" attribute2="value2"...>
...(text or more tags go here)...
</tagname>

Tags may have multiple attributes, and the order of the attributes is irrelevant.

Attributes are almost always optional. They add some sort of effect if you put them in, but you usually won't get in trouble if you leave them out. Always remember: if you forget to add something or make a mistake, the browser is supposed to do nothing. That's usually a good thing.

Note that each tag has a list of permitted attributes. You cannot freely add any attribute to any tag and expect it to work.

source

Link to Apple

<a href="http://www.apple.com">Link to Apple</a>

The <a> tag (or, "anchor" tag) allows us to create an HTML link to another web page. We specify the location with the href attribute, which we set to the value, "http://www.apple.com". The results look like this:

results

Link to Apple

If you click the link, you will indeed go to Apple.

Similarities to Tags

As with tags:

Quote Marks

The quoting of attributes is a key difference between HTML and XHTML. See the XHTML section for details.

Attributes must be contained within quotes. href=http://www.yahoo.com is an invalid attribute. If you fail to quote attributes, the browser will interpret certain special characters (e.g. < and >) as the end of the attribute or tag. The resulting garbled XHTML will not be pretty.

Don't forget to close your quote marks. If you don't, your attribute will "continue" until the next quote mark... which could be a long while. Again, you'll notice the garbled results immediately, although tracking down the source of the problem might take some work.