HTML Tutorial Part 1: Basics, Headings, Text Formatting and Colors
Lessons 1 to 11 of 38. Start from zero: what HTML is, how a page is structured, headings, paragraphs, text formatting, quotations, formulas and colors.
In this part
1. Basic Introduction (Basics)
- 1. What HTML is and what it is not
Understand the real difference between a programming language and a markup language - 2. Difference between Tag, Element and Attribute
The detailed anatomy of Tag vs Element vs Attribute - 3. HTML5 Boilerplate Code (Line-by-Line Explanation)
Understand every single word of DOCTYPE, html, head, meta, viewport, body
2. Headings and Text
- 4. All 6 Headings from H1 to H6 (Headings H1-H6)
<h1>, <h2>, <h3>, <h4>, <h5>, <h6> - the exact meaning and level of each - 5. Paragraphs, Line Breaks and Dividers (<p>, <br>, <hr>)
Spacing between text, starting a new line and drawing a dividing line - 6. Preformatted Text (<pre> Tag)
Preserving spaces, tabs and Enter: what you write is what you see - 7. <b> vs <strong> and <i> vs <em>
The difference between purely visual styling and semantic importance - 8. Text Marking and Editing (<mark>, <del>, <ins>, <small>)
Highlighting, striking out old prices, adding new prices and small text - 9. Maths and Science Formulas (<sub> and <sup>)
Writing chemical and mathematical equations like H2O, CO2 and (A+B)2 - 10. Quotations and Abbreviations (<blockquote>, <q>, <abbr>, <bdo>)
Writing quotes, abbreviations and writing text in the reverse direction - 11. HTML Colors (Colors: Names, HEX, RGB, RGBA, HSL)
4 ways to decorate a website with vibrant and attractive colours
1. Basic Introduction (Basics)
1. What HTML is and what it is not
Understand the real difference between a programming language and a markup language
Real-life analogy
Think of how a house is built: HTML is the skeleton of that house, made of bricks, rebar and cement. CSS is its plaster, window curtains and paint, and JavaScript brings movement to it, like electric fans, lifts and sensors!
Explanation
HTML stands for HyperText Markup Language. It is the foundational structure of every website in the world.
- HyperText: This means text that has links to other pages embedded in it (a different page opens the moment you click).
- Markup Language: It is not a programming language (like C++ or Java). It has no if-else, math calculations or loops. It only uses tags (< >) to tell the browser what each thing on the screen is.
- HTML file extension: It is always
.htmlor.htm(for exampleindex.html).
Golden rules
- HTML is case-insensitive, but writing
<p>in lowercase is always considered the best international standard. - Most tags need a matching closing tag
</tag>. Empty (void) tags such as<br>,<hr>and<img>do not.
Common mistake
Treating HTML as a programming language. HTML does not write logic; it only prepares the outline of the page.
Example code
<!DOCTYPE html>
<html>
<head>
<title>My First Website</title>
</head>
<body style="font-family: sans-serif; text-align: center; padding: 25px;">
<h1 style="color: #059669;">Hello World!</h1>
<p style="color: #475569; font-size: 14px;">I have started my first HTML coding today!</p>
<button style="background: #2563eb; color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: bold;">
Click me!
</button>
</body>
</html>
Quick quiz
What is the correct full form of HTML?
- HyperText Markup Language
- HighText Machine Language
- HyperTool Multi Language
- Home Tool Markup Language
Show answer
Answer: HyperText Markup Language
The correct full form of HTML is 'HyperText Markup Language'.
2. Difference between Tag, Element and Attribute
The detailed anatomy of Tag vs Element vs Attribute
Real-life analogy
If a tag is a 'person', then an attribute is the 'colour of their clothes' or their 'height'. In other words, an attribute gives a tag additional information.
Explanation
Students get most confused about these three terms:
- Tag: A word written inside angle brackets (for example
<p>to start and</p>to close). - Element: The whole group, from the opening tag through the closing tag and the content between them, is called an element.
- Attribute: It is always written inside the opening tag and gives the tag extra instructions (for example
src="photo.jpg"orhref="https://..."). It always comes as aname="value"pair.
Golden rules
- Always enclose attribute values in quotes
"...". - Attributes always go inside the opening tag, never in the closing tag.
Common mistake
Forgetting to add quotes, such as <a href=https://google.com>. This can break the code.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<!-- href, target and style are Attributes here -->
<a href="https://google.com" target="_blank" style="color: #2563eb; font-weight: bold; text-decoration: underline;">
Open Google (New Tab)
</a>
</body>
</html>
Quick quiz
In <p class='lead'>Hello</p>, what is 'class="lead"' called?
- Tag
- Element
- Attribute
- Entity
Show answer
Answer: Attribute
The additional information given inside a tag is called an Attribute.
3. HTML5 Boilerplate Code (Line-by-Line Explanation)
Understand every single word of DOCTYPE, html, head, meta, viewport, body
Real-life analogy
Just as a letter has the address written on the envelope at the top (Head) and the actual message inside (Body), every HTML page has a Head and a Body in the same way.
Explanation
These 5 lines are 100% mandatory in every modern web page:
<!DOCTYPE html>: Tells the browser that this is a modern HTML5 page. It is not a tag; it is a Declaration.<html lang="en">: This is the main Root element inside which the entire website lives.<head>: It holds the page's metadata (title, language, screen size settings), which does not appear directly on screen as content.<meta charset="UTF-8">: This ensures that Hindi, emojis (😀) and so on display correctly without breaking.<body>: The most important! Everything that the user sees on screen (text, buttons, photos) is written inside the body.
Golden rules
- There should be only one
<body>and only one<head>on the whole page.
Common mistake
Writing a Paragraph or Image inside the <head> tag. Remember, the head holds only settings; visible content goes in <body>.
Example code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Boilerplate Test</title>
</head>
<body style="font-family: sans-serif; padding: 20px;">
<h2 style="color: #059669;">The boilerplate is working correctly!</h2>
<p>This text is written inside <body>.</p>
</body>
</html>
Quick quiz
Inside which tag is all the content visible on screen (text, photos, buttons) written?
- <head>
- <title>
- <body>
- <meta>
Show answer
Answer: <body>
Only the content of the <body> tag appears in the browser's main window.
2. Headings and Text
4. All 6 Headings from H1 to H6 (Headings H1-H6)
<h1>, <h2>, <h3>, <h4>, <h5>, <h6> - the exact meaning and level of each
Real-life analogy
Think of a whole book: the book's title is H1, a Chapter is H2, the main topic of a chapter is H3, a sub-point within a topic is H4, a side note or hint is H5, and the footnote at the very bottom is H6!
Explanation
HTML has exactly 6 levels of headings. They are used not just to make text look bigger but to define the page's outline (Hierarchy):
Golden rules
- Never skip levels: don't jump straight from H1 to H3 or H4. Always follow the logical order H1 -> H2 -> H3.
- Don't use H1 or H2 just to make the font size bigger; use the CSS 'font-size' property to change font size.
Common mistake
Putting H1 five times on the same page. This confuses Google's search bot and lowers the website's SEO ranking.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 15px;">
<h1 style="color: #b91c1c; margin: 4px 0;">H1: The Complete Guide to Web Development</h1>
<h2 style="color: #c2410c; margin: 4px 0;">H2: Chapter 1 - Front-End Technologies</h2>
<h3 style="color: #b45309; margin: 4px 0;">H3: 1.1 The Basics of HTML5</h3>
<h4 style="color: #1d4ed8; margin: 4px 0;">H4: Introduction to Tags and Elements</h4>
<h5 style="color: #4338ca; margin: 4px 0;">H5: Special Hint for Students</h5>
<h6 style="color: #475569; margin: 4px 0;">H6: Copyright 2026 - All Rights Reserved</h6>
</body>
</html>
Quick quiz
Which heading is most appropriate for showing a book's 'Chapter Title' on a web page?
- <h1>
- <h2>
- <h5>
- <h6>
Show answer
Answer: <h2>
The main title of the page is <h1>, while <h2> is used for the chapters/sections within it.
5. Paragraphs, Line Breaks and Dividers (<p>, <br>, <hr>)
Spacing between text, starting a new line and drawing a dividing line
Real-life analogy
In a newspaper, the stories are divided into paragraphs, the break between lines within a paragraph is <br>, and the black dividing line between two stories is <hr>.
Explanation
The 3 basic tags for arranging text into paragraphs:
<p>: For writing a normal paragraph. The browser automatically leaves a little empty space (margin) above and below it.<br>: Line Break. Used when you want to move to the next line without starting a new paragraph (as in a poem or an address). It is an Empty Tag that has no closing tag.<hr>: Horizontal Rule. Draws a horizontal line (a dividing line) on the page. This is also an Empty Tag.
Golden rules
- Don't use
<br>10 times to change lines in a paragraph; use CSS margin to increase the distance. <br>and<hr>do not need to be closed.
Common mistake
Pressing the spacebar 10 times in HTML to get 10 spaces. The browser collapses those 10 spaces into just 1 space.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 15px;">
<p>This is the first paragraph.<br>This is the second line of the same paragraph (via <br>).</p>
<hr style="border: 0; border-top: 2px dashed #94a3b8; margin: 15px 0;">
<p>This is the second, independent paragraph that begins after the horizontal rule (<hr>).</p>
</body>
</html>
Quick quiz
Which tag is used in HTML to draw a horizontal divider line?
- <line>
- <divider>
- <hr>
- <br>
Show answer
Answer: <hr>
<hr> stands for Horizontal Rule, which draws a dividing line on the page.
6. Preformatted Text (<pre> Tag)
Preserving spaces, tabs and Enter: what you write is what you see
Real-life analogy
Just as whatever you type on a typewriter is printed on the paper exactly as it is, with no auto-formatting, the <pre> tag does the same thing.
Explanation
Normally in HTML, no matter how many spaces (Spacebar) or Enters you press, the browser ignores them and shows just a single space.
But the <pre> (Preformatted Text) tag preserves every space, tab and new line you give it 100%. By default it appears in a Monospace font.
Golden rules
<pre>is best suited for showing poems, ASCII art or programming code.
Common mistake
Expecting a normal paragraph to preserve spaces. Remember, only <pre> works for preserving spaces.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 15px;">
<!-- pre tag: all spaces and Enters will be preserved -->
<pre style="background: #0f172a; color: #38bdf8; padding: 15px; border-radius: 6px; font-size: 13px;">
Counting the stars
the night went by...
(Preformatted Text prints exactly as you write it)
</pre>
</body>
</html>
Quick quiz
Inside which tag are the spaces and line breaks shown by the browser exactly as written?
- <p>
- <code>
- <pre>
- <format>
Show answer
Answer: <pre>
The <pre> (Preformatted Text) tag doesn't let spaces and line breaks be lost.
7. <b> vs <strong> and <i> vs <em>
The difference between purely visual styling and semantic importance
Real-life analogy
<b> is just making the voice heavier, whereas <strong> is shouting a warning about danger so that even blind people can understand that this is very important!
Explanation
Students often think <b> and <strong> are the same, but there is a deep difference:
<b>(Bold): Only makes the text thick/bold. It carries no special semantic meaning.<strong>(Strong Importance): It makes the text bold and also tells search engines and screen readers that this is extremely important information or a warning.<i>(Italic): Only slants the text (for example, a word from a foreign language).<em>(Emphasis): Slants the text and also puts special stress (Emphasis) on that word when spoken.
Golden rules
- For Search Engine Optimization (SEO) and accessibility, always prefer
<strong>and<em>.
Common mistake
Using only <b> in a warning message. Screen readers used by visually impaired people don't stress <b>; they stress only <strong>.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px; line-height: 1.8;">
<p>This is only <b>visual bold (b)</b>.</p>
<p>Caution: This is an <strong>extremely important warning (strong)</strong>!</p>
<p>This is only an <i>italic word (i)</i>.</p>
<p>Please pay <em>special attention (em)</em> to this!</p>
</body>
</html>
Quick quiz
Which semantic tag marks a word as 'extremely important' for screen readers and search engines?
- <b>
- <bold>
- <strong>
- <important>
Show answer
Answer: <strong>
The <strong> tag makes the text bold and also raises its semantic importance.
8. Text Marking and Editing (<mark>, <del>, <ins>, <small>)
Highlighting, striking out old prices, adding new prices and small text
Real-life analogy
A sale board in a shop: the old price is crossed out with a pen (<del>), the new price is written below (<ins>) and the discount is coloured with a highlighter (<mark>)!
Explanation
The 4 main editing tags used in e-commerce and documents:
<mark>: Highlights the text in yellow.<del>: Draws a line through removed or old text (Strikethrough).<ins>: Shows newly added text underlined (Underline).<small>: Makes the text one level smaller than normal size (for legal terms).
Golden rules
- The
<del>and<ins>pair is best for showing discounts or offers.
Common mistake
Using only CSS to strike out the old price. Using <del> is the correct semantic standard.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<h3 style="margin-top: 0;">Blockbuster Offer:</h3>
<p style="font-size: 16px;">
Old price: <del style="color: #dc2626;">₹1,999</del> <br>
New price: <ins style="color: #16a34a; font-weight: bold;">₹699</ins>
(<mark style="background: #fef08a; padding: 2px 6px;">Save 65%</mark>)
</p>
<p><small style="color: #64748b;">*Terms and conditions apply (Small Text)</small></p>
</body>
</html>
Quick quiz
Which HTML tag is used to colour text with a yellow highlighter?
- <highlight>
- <mark>
- <yellow>
- <color>
Show answer
Answer: <mark>
The <mark> tag automatically adds a yellow highlight to the text background.
9. Maths and Science Formulas (<sub> and <sup>)
Writing chemical and mathematical equations like H2O, CO2 and (A+B)2
Real-life analogy
Sub stands for Submarine (which goes below the water), and Sup stands for Superman (who flies up in the sky)!
Explanation
Both of these tags are essential for science and maths equations:
<sub>(Subscript): Shows a character half a level below the normal line and in a smaller size. Used in chemical formulas (for example water: H2O).<sup>(Superscript): Shows a character half a level above the normal line as an exponent (power). Used in mathematical formulas or dates (for example 10th or X2).
Golden rules
- Use
<sup>for dates too, such as26<sup>th</sup> January.
Common mistake
Mixing up the two names: remember 'Sub' goes below and 'Sup' goes above.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px; line-height: 2;">
<p>1. Sulphuric acid: <strong>H<sub>2</sub>SO<sub>4</sub></strong></p>
<p>2. Formula of glucose: <strong>C<sub>6</sub>H<sub>12</sub>O<sub>6</sub></strong></p>
<p>3. Algebra: <strong>(x + y)<sup>2</sup> = x<sup>2</sup> + 2xy + y<sup>2</sup></strong></p>
<p>4. Today's date: <strong>15<sup>th</sup> August</strong></p>
</body>
</html>
Quick quiz
Which tag is used in maths to write an exponent (such as X to the power 2)?
- <sub>
- <sup>
- <power>
- <up>
Show answer
Answer: <sup>
<sup> (Superscript) shows text above the normal line as an exponent.
10. Quotations and Abbreviations (<blockquote>, <q>, <abbr>, <bdo>)
Writing quotes, abbreviations and writing text in the reverse direction
Real-life analogy
Reading out a great person's long thought on a stage is a blockquote, and saying a short phrase in conversation is the q tag.
Explanation
Special tags related to quotations and abbreviations:
<blockquote>: A large paragraph taken from another source. The browser shows it slightly indented.<q>: A short inline quote. The browser automatically puts double quotation marks (" ") on both sides of it.<abbr>: Abbreviation. You write its full name in thetitleattribute, and a tooltip appears when the mouse is moved over it.<bdo dir="rtl">: Bi-Directional Override. Used to reverse the direction of the text (to change Left-to-Right into Right-to-Left).
Golden rules
- Always add the
titleattribute in<abbr>so that the full form is clear to the user.
Common mistake
Typing "..." directly from the keyboard for a short quotation. Using <q> is considered more semantic.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<blockquote cite="https://example.com" style="border-left: 4px solid #0284c7; padding-left: 12px; margin: 10px 0; background: #f8fafc; font-style: italic;">
"Arise, awake, and do not stop until the goal is reached."
</blockquote>
<p>Gandhiji's slogan: <q>Do or die</q></p>
<p><abbr title="World Health Organization" style="text-decoration: underline dotted; cursor: help;">WHO</abbr> looks after health care.</p>
<p>Reversed text: <bdo dir="rtl" style="color: #dc2626; font-weight: bold;">This is written backwards</bdo></p>
</body>
</html>
Quick quiz
When double quotes (" ") should be automatically added on both sides of a short sentence, which tag is used?
- <quote>
- <q>
- <blockquote>
- <cite>
Show answer
Answer: <q>
The <q> tag automatically adds quotes on both sides of inline quotations.
11. HTML Colors (Colors: Names, HEX, RGB, RGBA, HSL)
4 ways to decorate a website with vibrant and attractive colours
Real-life analogy
Just as a painter can mix red, green and blue to make any new colour in the world, a computer monitor makes millions of colours from these three colours.
Explanation
The 4 main formats for specifying colours in HTML:
- Colour Names (Color Names): Write the name directly, such as
Red,Tomato,DodgerBlue,SlateGray(140 standard names are valid). - HEX code (Hexadecimal): The most popular way, such as
#ff6347(a 6-digit code with #). - RGB values:
rgb(255, 99, 71)where each colour ranges from 0 to 255. - RGBA values: Here 'A' (Alpha) means transparency (Opacity), such as
rgba(0, 0, 0, 0.5)(50% transparent).
Golden rules
- Never forget to put the hash
#at the front of a HEX code. - Keep good contrast between text and background so that it is easy to read.
Common mistake
Making a mistake in a 3-digit or 6-digit HEX code. If you give an invalid code, the colour may turn black or transparent.
Example code
<!DOCTYPE html>
<html>
<body style="font-family: sans-serif; padding: 20px;">
<div style="background-color: Tomato; color: white; padding: 8px; margin-bottom: 6px; border-radius: 4px;">1. By name: Tomato</div>
<div style="background-color: #2563eb; color: white; padding: 8px; margin-bottom: 6px; border-radius: 4px;">2. HEX code: #2563eb (Royal Blue)</div>
<div style="background-color: rgb(16, 185, 129); color: white; padding: 8px; margin-bottom: 6px; border-radius: 4px;">3. RGB value: rgb(16, 185, 129)</div>
<div style="background-color: rgba(15, 23, 42, 0.8); color: #38bdf8; padding: 8px; border-radius: 4px;">4. RGBA value (80% opaque)</div>
</body>
</html>
Quick quiz
Which symbol must be placed in front of a HEX colour code?
- $
- &
- #
- @
Show answer
Answer: #
HEX colour codes always start with a hash '#', such as #ffffff (white).