HTML Tag Attributes

Bookmark
What is an Attribute and how to use it with HTML Tags.
  • Attribute adds meta information to a HTML Tag element.
  • A HTML can have more than one Attribute.
  • Attributes can be optional are mandatory depending on the HTML Tag element.
  • Attributes are added to the Start Tag element.
  • Attributes have a name and value.

HTML Tag Attribute Example

<a href="http://www.tutorialwalk.com">This is a link</a>

Above given is an example of a HTML Anchor Tag. href is the attribute that adds the url address information to the anchor tag element. href is the attribute name and address is the attribute value.

Let us see one more example using img tag element,

<img src="photo.jpg" width="300" height="150" >

In the above HTML Image Tag element, you can see multiple attributes width, height and src. src is the attribute name and photo.jpg is the address of the file referred. width is the attribute name and 300 is the attribute value in pixels.

You can learn more about the anchor and img tag in their respective chapters.

HTML Tag Attributes General Guidelines

  • Though it is not mandatory, use lower case letters for attributes.
  • Generally double quotes are used to specify the attribute values. Single quote can also be used. Even without quotes will also work in most of the cases as HTML5 does not mandate the use of quotes.

Exception Occured:

TypeErrorException
Messageerror_log(app.log): Failed to open stream: Permission denied
File/home/dh_czz6eb/tutorialwalk.com/common/error.php
Line36
Trace#0 (): log_error(2, 'error_log(app.log): Failed to open stream: Permission denied', '/home/dh_czz6eb/tutorialwalk.com/common/error.php', 36)
#1 /home/dh_czz6eb/tutorialwalk.com/common/error.php(36): error_log('16-04-2024 01:27:58 am (IST),/home/dh_czz6eb/tutorialwalk.com/common/common.php,193,0,ErrorException,Optional parameter $per_page declared before required parameter $href is implicitly treated as a required parameter,/html/html-tag-attributes.html,#0 /home/dh_czz6eb/tutorialwalk.com/common/error.php(115): log_error(8192, 'Optional parame...', '/home/dh_czz6eb...', 193)
#1 [internal function]: check_for_fatal()
#2 {main}
', 3, 'app.log')
#2 /home/dh_czz6eb/tutorialwalk.com/common/error.php(8): log_exception(ErrorException)
#3 /home/dh_czz6eb/tutorialwalk.com/common/error.php(115): log_error(8192, 'Optional parameter $per_page declared before required parameter $href is implicitly treated as a required parameter', '/home/dh_czz6eb/tutorialwalk.com/common/common.php', 193)
#4 (): check_for_fatal()
REQUEST_URI/html/html-tag-attributes.html