Skip to content

HTML Attributes

Attributes are used to change the default behavior of a tag. Some tags require an attribute while others behave a certain way until you change it by adding a specific attribute. All attributes are defined within the opening tags brackets (<>).

Some attributes are used to change how something is formated and others are used as a method of classifiying your tags so you can isolate and format those tags using Cascading Style Sheets (CSS).

A basic attribute could look like:

<p align="center"> Hello World</p>

Hello World

As you can see, by using the align attribute and giving it a value of "center", it aligns the text appropriately.

Class and ID Attributes

As stated earlier, you can use an attribute as a method of classifiying a tag, Say you want to have all even paragraphs to look a certain way and all odd paragraphs to look different from the even paragraphs? You would need to either the class or id attribute.

<p class="even">Some text</p>
<p class="odd">Some more text</p>

Some Text

Some more text

I can then use CSS to isolate the "even" and "odd" classes and style them differently.

The id attribute acts similar to the class attribute, except for one main difference. The id attribute can only be used once per page, while the class attribute can be used multiple times.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <p><b><i><pre><a><img><em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><h1><h2><h3><h4><h5><h6>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

More information about formatting options