1. Technology

How to Add an Attribute to an HTML Tag


Attributes modify HTML tags and provide additional information to the web browser. They are easy to add to HTML tags.

A basic HTML tag starts with the < character, the tag name, and finishes with the > character. For example:


To add an attribute to your HTML tag, put a space after the tag name. Then add the attribute name, an equal sign, and the attribute value in quotation marks. For example:

<p style="color:red;">

Tags can have multiple attributes. Separate each attribute from the others with a space.

<p style="color:red;" title="first paragraph">

It's a good idea to surround all attribute values with double quote marks. You can also use single quotes. If you're writing HTML (as opposed to XHTML), you can leave off the quotation marks if there are no spaces in your attribute value. But I don't recommend getting into that habit. Quoting attributes is a good idea to keep your HTML from having problems.

©2014 About.com. All rights reserved.