TRENDING TOPICS

×

What is the difference between tag and attribute in HTML?

By: Narges Bahar | 15 July 2019

S

Sandeep Singh

06 May 2020

Difference between tag and attribute in HTML

Difference between tag and attribute in HTML HTML tag is the basic building block of HTML in other words an HTML tag is a way of representing HTML elements. An HTML tag is independent HTML element.

HTML attribute is used to define the characteristics of an HTML element. HTML attribute is always dependent on HTML tags.

Difference between tag and attribute in HTML Explained

  • You can suppose HTML tag as a brick of a building then attributes can be color of brick, the height of brick, the width of the brick, type of brick, etc.
  • HTML tags can be either single or in pairs, in most cases, tags are in pairs.
  • The tags in pairs are called opening tag and closing tag for example <p> is opening tag and </p> its the closing tag.
  • There are few single tags in HTML for example </br>, <hr> etc.

Examples of HTML Tags

<p>Hello this is a paragraph</p>

<h1>Let's learn tag in HTML</h1>

HTML attributes are used to represent the characteristics of an HTML element. They are always used with HTML tags

Example of HTML Attribute

<p id="p1" style="color:green">Hello this is a paragraph</p>

<h1 id="h1" class="my_h1">Let's learn tag in HTML</h1>

In above example id, style, class are the attributes of the tags <p> and <h1>

I hope now you are totally clear about difference between tag and attribute in HTML. If still there is any confusion then you can reply to my answer and share your problem.

0 votes

Your Answer

Advertise With Us

We offer sponsored posts and guest posts with do-follow links, back-links, and other advertising services, To advertise email us at "advertise@gdatamart.com"

© 2021 GDATAMART.COM (All Rights Reserved)