HTML

Getting to Know HTML Tags, Elements, and Attributes for Beginners

Tag, element and attribute: three HTML words beginners often mix up. Here's what each one means, explained simply with examples.

RazakTerra
Reading time
2 min read
Comments
Discussion
Getting to Know HTML Tags, Elements, and Attributes for Beginners
On this page
  1. What is a Tag?
  2. What is an Element?
  3. What is an Attribute?
  4. Quick Comparison
  5. Putting It All Together

What is a Tag?

A tag is the basic building block of HTML. It’s written using angle brackets < >. There are two types:

Opening tag → <p>

Closing tag → </p>

Some tags are self closing (also called empty tags), like:

HTML
<br />
<img />
<input />

Think of tags as the labels that tell the browser what kind of content you’re adding.

What is an Element?

An element is the complete package. It includes:

The opening tag The content inside The closing tag

Example:

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

Here, the whole thing (<p>This is a paragraph.</p>) is called a paragraph element. So remember:

Tag = just the <p> or </p> Element = the full thing with content inside

What is an Attribute?

An attribute gives extra information about an element. It always goes inside the opening tag and usually comes in a name value pair. Basic format:

HTML
<tag attribute="value"></tag>

Common examples:

HTML
<!-- The src attribute tells the browser where the image is -->
<img src="photo.jpg" alt="A cute cat" />

<!-- The href attribute is the link destination -->
<a href="https://example.com">Visit Example</a>

<!-- The class attribute is used for styling or JavaScript -->
<p class="highlight">This text is special</p>

<!-- The id attribute gives a unique name to an element -->
<h1 id="main-title">Welcome</h1>

Quick Comparison

Term What it is Kegunaan
Tag The label in angle brackets <p>, </p>, <img>
Element Tag + content + closing tag <p>Hello</p>
Attribute Extra info inside the opening tag src=“photo.jpg”, class=“box”
Tag heading dan kegunaannya.

Putting It All Together

Here’s a small example that uses all three:

HTML
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Tags, Elements & Attributes</title>
  </head>
  <body>
    <h1 id="title">Hello World</h1>
    <p class="intro">This is a <strong>paragraph</strong> element.</p>
    <img src="cat.jpg" alt="A sleeping cat" width="300" />
    <a href="https://google.com" target="_blank">Go to Google</a>
  </body>
</html>

In this code:

<h1>, <p>, <img>, <a> are tags The full <h1 id="title">Hello World</h1> is an element id=“title”, class=“intro”, src=“cat.jpg”, href=“…”, target=“_blank” are attributes

Quick Tips for Beginners

Always close your tags (unless they’re self closing). Attribute values should usually be wrapped in quotes (” “). You can have multiple attributes in one tag, just separate them with spaces. Not every element needs attributes only add them when you need extra info.

Once you understand the difference between tags, elements, and attributes, reading and writing HTML becomes way easier. These three concepts are the foundation of almost everything you’ll do in HTML.

Written by

Razak

Writes about the web, slowly, and builds small tools on the side.

Discussion

Comments

Loading comments…

Keep reading