HTML Attributes: An Introduction

HTML attributes provide extra information about an HTML element. You can use them to insert JavaScript or CSS style rules into the element. You can use them to assign a unique ID to the element. You can use attributes to do all kinds of cool things. But right now we don’t want to learn all the specifics, we just want to get a general feel for what they look like.

The Basic Form of HTML Attributes

All HTML attributes have a name and a value. And they take the following form: name="value".

Please note that the value is always contained within a pair of quote marks. You can use a pair of double quotes ("value") or a pair single quotes ('value'). I usually use double quotes.

The Proper Placement and Spacing of HTML Attributes

Attributes are placed within the opening tag just after the tag’s keyword. A tag can contain more than one attribute.

At least one space must separate the tag’s keyword and the first attribute. At least one space must separate each of the attributes from each other. A space is not required between the last attribute and the right angle bracket (>) that completes the opening tag.

Diagram showing proper placement and spacing of HTML attributes.

Some Examples of HTML Attributes

Below are some examples of some tags with attributes. Don’t worry about what the tags or attributes mean or do at this point. I just want you to see some examples of what HTML attributes look like:

table tag
<table cellspacing="10"></table>
image tag
(src & id)
<img id="image1" src="some‑image.jpg" />
anchor tag
<a href="">click here</a>

If the browser encounters an attribute it doesn’t recognize, it ignores it. Usually, this means you misspelled the attribute’s name or provided a value that doesn’t make any sense.

Well, I think that’s enough about HTML attributes — at least for now. Next we’ll talk about how you shouldn’t overlap HTML tags.

This entry was posted in HTML Tutorials. Bookmark the permalink.

Comments are closed.