html 101

HTML Attributes Explained

In that last example, you saw something a bit funny:

What's that "src=" business all about? Most HTML tags can take additional parameters that tell them how to behave, or how to display. These additional parameters are called "attributes." The img tag, which is used to insert an image in a page, is meaningless unless you tell it which image to insert! In the case of the img tag, the src attribute is required.

In other cases, attributes are optional. For example, the <hr /> tag creates a horizontal rule across the page. But what if you only want the rule to go  halfway across the page? In that case, you could use the "width" attribute on the hr tag:

Note that the value of each attribute is always enclosed in double quotes.

In many cases, you'll be putting multiple attributes on a tag. In that case, simply separate them with spaces. It does not matter what order attributes come in. For example:

There are many attributes, and not all of them apply to all tags. Until you get comfortable with the range of available attributes, you'll want to refer to an official listing, such as this one hosted by w3schools. Click on any tag name in that list to see that tag's available attributes.

In this tutorial, we'll work a bit with the "style" attribute, which takes this form:

Stylistic declarations like this are generally handled by an external CSS stylesheet, but for the sake of simplicity, we'll be placing styles directly into our tags as attributes.