Table of Contents
- Hello World!
- Understanding Tags and Structure
- Whitespace in XHTML
- Breakdown of a Tag
- Attributes
- Paragraphs and Line Breaks
- Validation and Browser Tools
Basic Structure
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:
- attribute: Defines the attribute that you're using.
- value: Selects a particular kind of behavior for the attribute.
<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.
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:
If you click the link, you will indeed go to Apple.
Similarities to Tags
As with tags:
-
All attributes must be lowercase.
STYLEis an invalid attribute. -
Whitespace is irrelevant. You may freely insert spaces, tabs, or even carriage returns between attributes, as long as you don't forget the closing angle bracket at the end of the tag (
>). -
Incorrect attributes are ignored. Misspelled attributes, such as
hhref="http://www.apple.com"have no effect. As with tags, browsers attempt to ignore attributes that they do not understand. Misspelling "href" means that your link will not appear. However, if you misspell "http://www.apple.com", your link will appear... but it won't take you to the right place.
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.
