What is the difference between tag and attribute in HTML?

Last Update: Apr 27 2024 | BY: Narges Bahar

S

Sandeep Singh

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

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

LifeStyle & Fun

© 2024 GDATAMART.COM (All Rights Reserved)