Cyber Code Academy
Tutorials Academy Courses
Home / html-tutorials-md / HTML Tags, Elements, and Attributes

HTML Tags, Elements, and Attributes

> Understand tag syntax, elements, nesting, attributes, and void elements in detail.

**Cyber Code Academy · HTML Tutorial · Lesson 04 · Beginner**

## 1. What is an HTML tag?
A tag is markup written between angle brackets. Most HTML elements use an opening tag and a closing tag.

“`html

This is a paragraph.

“`

– `

` is the opening tag.
– `This is a paragraph.` is the content.
– `

` is the closing tag; the slash identifies it as a closing tag.

## 2. What is an HTML element?
An element is the complete structure: opening tag, content, and closing tag. Elements can contain text or other elements.

“`html

Learn HTML with practice

“`

The h1 element contains text and a nested strong element. The nested element gives the word HTML strong importance.

## 3. Opening tags, closing tags, and void elements

Most elements have both opening and closing tags:
“`html

About Us

We teach web development.

View courses
“`

Void elements do not wrap content and must not have an end tag. Examples include:
“`html
Academy logo


“`

Do not write a closing tag for a void element. In HTML, a trailing slash is optional and does not make a void element an XML-style self-closing element.

## 4. What are attributes?
Attributes provide additional information about an element. They are written in the opening tag, commonly as name-value pairs.

“`html

Visit Example

“`

Here:
– href gives the destination.
– target controls where the link opens.
– rel describes the relationship to the destination.

Use quotation marks around attribute values. This keeps markup predictable, especially when values contain spaces.

## 5. Common global attributes

Global attributes can be used on many HTML elements:

| Attribute | Purpose |
|—|—|
| id | Unique identifier in the document |
| class | Reusable name for styling or scripting |
| title | Advisory information, often shown as a tooltip |
| lang | Language of the element’s content |
| hidden | Indicates content should not be rendered |
| tabindex | Controls focusability and sequential keyboard order |
| data-* | Stores custom data for scripts |

Example:
“`html

Welcome to HTML.

“`

An id should be unique in the document. Classes may be reused on many elements.

## 6. Boolean attributes

Some attributes are boolean. Their presence means true; absence means false.

“`html

Course details

The course includes examples and exercises.

“`

Writing `required=”false”` does not make the control optional. The attribute is still present, so it is true. Remove the attribute to make it false.

## 7. Attribute values and safe markup

Use valid attribute values and escape special characters when necessary. For example, use `&` to represent an ampersand in HTML text or an attribute value.

Avoid putting private data, passwords, API keys, or confidential information into attributes. Browser-delivered HTML can be inspected by visitors.

## 8. Nesting elements correctly

Elements may be nested, but they must close in the correct order.

Correct:
“`html

This is very important information.

“`

Incorrect nesting:
“`html

This is important


“`

The browser may attempt to repair malformed markup, but its result may not match your intention.

## 9. Block and inline behaviour

HTML semantics and CSS display behaviour are different ideas. Many elements normally participate in block or inline layout:

– A paragraph normally starts a new block.
– A span normally flows inside a line of text.
– A div is a generic block container by default.
– An anchor normally behaves like an inline element.

CSS can change display behaviour, but changing display does not change the element’s semantic meaning.

## 10. Common mistakes

– Forgetting a closing tag where one is required.
– Closing tags in the wrong order.
– Reusing the same id multiple times.
– Typing an attribute outside its opening tag.
– Using invalid attribute names.
– Assuming required=”false” disables required validation.
– Forgetting that HTML source and attributes are visible to visitors.

## 11. Practice exercises

1. Create a paragraph with a strong element nested inside it.
2. Create a link with href, target, and rel attributes.
3. Add id and class to different elements.
4. Create a required email input and a disabled button.
5. Intentionally create incorrect nesting, inspect the browser DOM, then fix it.

## 12. Knowledge check

1. What is the difference between a tag and an element?
2. What is a void element? Give three examples.
3. Where are attributes written?
4. How is id different from class?
5. Why does required=”false” still make a field required?
6. Why should HTML attributes never contain secrets?

## Summary
Tags define markup, elements form the document structure, and attributes add information or behaviour. Correct nesting and meaningful element choices help keep HTML reliable and accessible.

**Next lesson:** HTML Headings and Paragraphs.

Want to learn this professionally?

Explore practical IT training at Cyber Code Academy.

View Academy Courses