Member-only story

Difference between tag and attribute

Pravin M
2 min readFeb 21, 2024

--

Difference between tag and attribute
Difference between tag and attribute

Source:- Difference between tag and attribute

For more questions and answers visit our website at Frontend Interview Questions

  1. Tag:

Within the domain of markup languages like HTML, a tag serves as a foundational building block. Tags are instrumental in defining the layout and substance of elements present on a webpage. They are composed of angle brackets (“<” and “>”) and usually come in pairs: an opening tag and a closing tag. The opening tag signifies the commencement of an element, while the closing tag denotes its conclusion.

For example, in HTML:


<p>This is a paragraph.</p>

In this case, `<p>` is the opening tag, and `</p>` is the closing tag. Together, they define a paragraph element on the webpage.

2. Attribute:

An attribute encompasses additional particulars that can be appended to an HTML tag. These attributes are inserted within the opening tag of the element and generally comprise a name and a value. The name and value are separated by an equals sign (“=”) and are enclosed in either double or single quotation marks.

For example, in HTML:


<a href="https://www.example.com">Visit Example Website</a>

In this example, `href` is an attribute of the `<a>` (anchor) tag. It specifies the hyperlink reference, or the URL that the anchor tag links to.

Conclusion:

In summary, a tag defines the type and structure of an HTML element, while an attribute provides additional information or settings for that element. Tags and attributes work together to create well-structured and interactive web content.

--

--

Pravin M
Pravin M

Written by Pravin M

I am a frontend developer with 10+ years of experience Blog :- https://www.frontendinterviewquestions.com

No responses yet