Basic HTML

Tag Attributes

Key points
  • Some HTML tags require attributes to give the web browser more information.
  • HTML tag attributes are in the form name="value".
  • A single tag can have multiple attributes, but cannot have the same attribute more than once.

For some tags, like the <a> and <img> from the previous section, web browsers need extra information than just the name of the tag. HTML tag attributes gives browsers that extra information so it knows where to find an image, for example.

Attribute Format

Attributes have a specific format: name="value". Where name is the attribute's name, similar to a tag's name, and value is what the browser uses to determine what to do with the tag. Note that the quotation marks ("") around the value are not part of the value, but rather let the browser know where the value starts and where it ends. Here is an example of an attribute within the <a> tag:

Click to view Live Example

<a href="http://wikipedia.org">Click here</a>
An <a> tag with the href attribute

Some browsers allow HTML authors to leave out the quotation marks for short values, but it is not recommended nor considered correct HTML.

Multiple Attributes

A single HTML tag can have multiple attributes separated by a space. However, a single tag cannot have the same attribute more than once. For example, an <img> can have the src, width, and height attributes, but cannot have src twice.

Click to view Live Example

<img src="http://blog.spanglerco.com/headerS1.jpg" width="20px" height="20px" />
The <img> tag can also have the width and height attributes

For <img> tags, the width and height attributes are optional. The px at the end of the numbers mean pixels and will be discussed in the later section about HTML styles.