Using HTML Tag Attributes

HTML tags provide the foundation for web page design. To provide more flexibility with HTML design, attributes have been defined for HTML tags to alter the behavior of any particular HTML tag. There are many instances while designing a web page when you will want to change the default behavior of the tag. For instance, you might want to change the background color of the whole page or some section of the page. You might want to change the alignment of a section of text or apply a unique style to a tag’s representation. There are many instances when you would want to identify an HTML tag by giving it a name to identify it so that it can be referred to elsewhere. Some tags, such as the one used to present an image (

 Using HTML Tag Attributes

) don’t do much of anything without having at least one attribute defined. In the case of the image tag, you would need to have an attribute that tells the browser where the find the image to be displayed.

Some Examples of HTML Attributes

Using bgcolor and background with the body tag
A very visible example of the effect of an attribute used in an HTML tag is changing the background color or image for the entire body of a web page. Browsers understand that the contents of the tag will be displayed on the main part of the web page. By default, the background used by browsers when they encounter the tag is white. If you want a background color other than white, you would use the bgcolor attribute. The following tag changes the background color of a web page from the default white to gray:
If you want to have an image comprise the background for a web page, you could use the following code:

This example assumes that you have a folder on your web server called images, and that inside that folder there is an image named background.gif. In the case of a background image, if the image isn’t large enough to fill the entire background of your web page, the browser will repeat the image vertically and horizontally to fill the background.

Linking using the anchor tag
The world wide web’s fundamental usefulness hinges on its ability to link documents, providing web users with a quick connection from one page to another related page. Linking documents in HTML is done using the anchor () tag. The anchor tag by itself doesn’t tell the browser where to link. Instead, you have to include the href attribute as in the following example:

Visit our sponsor
This piece of HTML code tells the browser that the text “Visit our sponsor” is the anchor text for a link. When the user clicks on the anchor text, he is taken to the url oursponsorswebsite.com.
Displaying a picture using the image tag
HTML pages would be pretty boring without the use of images. The need to tell the browser where to find an image is a good example of how to use HTML attributes. Images are included using . Similar to the anchor tag example above, using the tag alone wouldn’t suffice. The image tag attribute “src” is required to tell the browser where to find the image to be displayed, as in the following example:

This block of code tells the browser to place an image in the document. The browser is instructed to get the logo.gif image from the images folder located in the top level folder for the document. You also notice a width attribute defined in the tag. This constrains the image to be 150 pixels wide. Conveniently, the height of the image is constrained proportionally when the width attribute is defined.

HTML Attributes Reference
Don’t feel like you have to memorize all the HTML tags and their corresponding attributes. Instead, it is convenient to access a reference when trying to determine which attributes can be used with particular HTML tags. The official definition for HTML tags and attributes can be found at www.w3.org You can also find other resources for understanding the same information by using a search engine to search for “html tags” or “html attributes”

Beyond HTML Attributes
In the mid-1990′s, a methodology called Cascading Style Sheets (CSS) was developed for use in web pages to make them more streamlined. CSS is a standard for defining the layout and formatting for a web page. Many of the attributes that were commonly used with HTML tags before CSS came around are now handles by CSS definitions. For designers unfamiliar with CSS or who, for whatever reason, don’t choose to use CSS, HTML attributes that overlap with CSS definitions can still be used to change the behavior of HTML tags. However, to be considered vogue in the world of web design, it is recommended that you learn and use CSS.

 Using HTML Tag Attributes

Richard Robbins is one of the founders of WebsiteTemplateDatabase.com, a resource for free blogger templates and free website templates

41X8scMJCaL. SL75  Using HTML Tag AttributesWhat Is HTML5?
HTML5: Everyone’s using it, nobody knows what it is. I realize that sounds more like a line out of an existential movie — mayb…
51Ti3mtvAqL. SL75  Using HTML Tag AttributesHTML Made Easy
This beginners guide to HTML teaches you everything you need to know to design and maintain simple websites using HTML. It presume…
51rvw49RejL. SL75  Using HTML Tag AttributesJavaScript and HTML5 Now
A decade ago, Ajax took the Web out of childhood, and now HTML5 and JavaScript are moving the Web into full adulthood. This insigh…
  • CommentLuv badge



    This blog uses premium CommentLuv which allows you to put your keywords with your name if you have had 3 approved comments. Use your real name and then @ your keywords (maximum of 3)