Every web page is built from elements: a start tag, some content and an end tag, such as <p>Hello</p>. Attributes go inside the start tag and add extra information, such as an id, a link address or a language. This lesson covers the everyday text elements, the difference between block and inline elements, the most useful attributes, comments and special characters.
In this lesson you will learn
- The parts of an HTML element
- Text elements such as
<strong>,<em>,<sub>and<br> - Global attributes:
id,class,title,lang,style - Block vs inline elements
- Comments and HTML entities like
<
Anatomy of an Element
In <a href="/learn/">Courses</a>, <a> is the start tag, href="/learn/" is an attribute (a name and a value in quotes), “Courses” is the content, and </a> is the end tag. Elements can be nested inside each other, but they must close in the reverse order they opened.
Text Elements and Attributes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Elements and attributes</title>
</head>
<body>
<h2 id="intro" title="Hover over me">Elements and Attributes</h2>
<p>This paragraph has <strong>strong</strong>, <em>emphasised</em> and
<mark>highlighted</mark> words.</p>
<p lang="bn">ঢাকা</p>
<p>Water is H<sub>2</sub>O and 10<sup>3</sup> is 1000.</p>
<p>Line one<br>Line two after a line break.</p>
<hr>
<p style="color: teal;">An inline style attribute makes this text teal.</p>
</body>
</html>
Result
<strong>marks important text (bold) and<em>marks emphasis (italic). Screen readers can stress them, which plain bold styling does not do.<mark>highlights,<sub>and<sup>write subscripts and superscripts.<br>and<hr>are void elements: they have no content and no end tag.idnames one unique element;titleshows a tooltip on hover;langtells browsers and screen readers the language of the text.- The
styleattribute applies CSS to one element. It is handy for quick tests, but a stylesheet is better for real sites.
Block vs Inline, Comments and Entities
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Block and inline</title>
<style>
div { background: #e0f2f1; margin: 4px 0; padding: 4px; }
span { background: #fff3cd; }
</style>
</head>
<body>
<div>A div is a block element: it starts on a new line.</div>
<div>Another div, stacked underneath.</div>
<p>A span is <span>inline</span>, so it sits <span>inside</span> the line.</p>
<!-- This comment is not shown in the browser -->
<p>5 < 7 & 7 > 5 © 2026</p>
</body>
</html>
Result
- Block elements (
div,p,h1–h6,ul) start on a new line and take the full width. - Inline elements (
span,a,strong,img) sit inside a line of text. <!-- ... -->is a comment; browsers ignore it.- Characters with special meaning are written as entities:
<for <,>for >,&for &,©for ©.
Common Global Attributes
| Attribute | Purpose |
|---|---|
id | A unique name, used for links (#id), CSS and JavaScript |
class | One or more reusable names for styling groups of elements |
title | Extra information shown as a tooltip |
lang | Language of the content, such as en or bn |
style | Inline CSS for one element |
hidden | Hides the element |
data-* | Custom data for scripts, such as data-price="250" |
Common Mistakes
- Overlapping tags like
<strong><em>text</strong></em>. Close the inner one first. - Reusing an
idon several elements. Use aclassinstead. - Using
<br>for spacing. Use CSS margins; keep<br>for real line breaks such as addresses. - Typing
<directly in text, which the browser may read as a tag.
Practice Exercises
Exercise 1. Write the chemical formula for carbon dioxide (CO₂) in HTML.
Show answer
<p>CO<sub>2</sub></p>
Exercise 2. Display the text <p> on a page without the browser treating it as a tag.
Show answer
<p>Use the <p> tag for paragraphs.</p>
Frequently Asked Questions
Are HTML tags case-sensitive?
No, <P> and <p> work the same, but lowercase is the standard style.
What is the difference between <b> and <strong>?
Both look bold. <strong> also says the text is important, which matters for accessibility; <b> is purely visual.
Summary
- An element is a start tag, content and an end tag; attributes live in the start tag.
- Block elements start new lines; inline elements flow within text.
idis unique,classis reusable.- Write special characters as entities.
Next: HTML Links and Images.
