Sep 1, 2026

Introduction: HTML Text Formatting

 

To modify the appearance and structure of text on a webpage.

HTML text formatting can be divided into two main categories: Logical Tags and Physical Tags.

1. Logical Tags

Logical tags convey the meaning or importance of the text without necessarily altering its visual appearance. These tags help browsers, search engines, and assistive technologies understand the purpose of the text.


<em>: Emphasizes text, typically rendered in italics. It implies that the text carries special importance or requires emphasis.

<strong>: Marks text as important, often displayed in bold. It implies the content is of strong importance.

2. Physical Tags

Physical tags directly affect how text looks on the webpage by changing the font, size, or style.


<b>: Displays text in bold without implying importance.

<i>: Italicizes text without any implied emphasis.

HTML Formatting Elements

1. <i> – To display text in italics without implying emphasis.

<i>This is italic text.</i>

2. <small> –  Renders text in a smaller font than the surrounding text.

<small>This text is smaller than the rest.</small>

3. <ins> – Marks text as newly added or inserted, often displayed with an underline.

<ins>This is inserted text.</ins>

4. <sub> – For subscripted text, often used in chemical formulas or footnotes.

H<sub>2</sub>O

5. <strong> – Emphasizes important text, often rendered in bold

The <strong> tag is semantically meaningful and indicates that the text is of high importance.

<strong>This text is bold and important.</strong>

6. <b> – Makes the text bold but does not imply any special significance.

<b>This is bold text.</b>

7. <mark> – Highlights text with a background color, similar to using a highlighter on paper.

<mark>This text is highlighted.</mark>

8. <del> – Strikes through text

The <del> tag is used to show that text has been deleted or is no longer relevant.

<del>This text is crossed out.</del>

9. <em> – Emphasizes text, typically italicized

The <em> tag is used for emphasized text and is usually rendered in italics to highlight importance.

<em>This text is emphasized.</em>

10. <sup> – Displays the superscripted text, commonly used in exponents or footnotes.

E = mc<sup>2</sup>

 

Basic text formatting elements : 

 Heading: <h1> , <h2> , <h3> , <h4> , <h5> , <h6>

Paragraph: <p> , 

Line Break: < br / > , 

<pre> 

White Space and Flow 

 If we put several consecutive spaces between two words, by default, only one space will be displayed. This is known as white space collapsing . 

Similarly, if you start a new line in your source document, or you have consecutive empty lines, these will be ignored and simply treated as one space, as will tab characters. 

 < p > This paragraph shows how multiple spaces between words are treated as a single space. This is known as white space collapsing, and the big spaces between some of the words will not appear in the browser.

 It also demonstrates how the browser will treat multiple carriage returns (new lines) as a single space, too. < /p > 

 As the browser treats the multiple spaces and several carriage returns (where text appears on a new line) as if there were only one single space. It also allows the line to take up the full width of the browser window. 

 Structuring Documents for the Web

 Creating Headings Using <hn>Elements 

 Heading indicate titles and subtitles within webpages to help structure and organize content, which can help search engines and readers understand and navigate the page.

These tags range from <h1> to <h6> (< h1 > , < h2 > , < h3 > , < h4 > , < h5 > , and < h6 >). 

The <h1> should be the page title that reflects the main topic, 

<h2> should be the most important subtopics, and so on.


Browsers display the <h1> element as the largest of the six and <h6> as the smallest.

Most browsers display the contents of the < h1 > , < h2 > , and < h3 > elements larger than the default size of text in the document. 

The content of the < h4 > element would be the same size as the default text, and the content of the < h5 > and < h6 >elements would be smaller unless you instruct them otherwise using CSS.

Creating Paragraphs Using the <p>Element 

 The < p > element offers another way to structure your text. 

Each paragraph of text should go in between an opening < p > and closing < /p > tag -

 < p > Here is a paragraph of text. < /p > 

 < p > Here is a second paragraph of text. < /p > 

 < p > Here is a third paragraph of text. < /p > 

 When a browser displays a paragraph, it usually inserts a new line before the next paragraph and adds a little bit of extra vertical space.


 Creating Line Breaks Using the <br/> Element 

 It starts on the next line. 

The <br/> element is an example of an empty element ; you don ’ t need opening and closing tags, because there is nothing to go in between them. 

 Note that the < br / > element has a space between the characters br and the forward slash. 

 You will often see these written like so: < br > , which is the way it was written in earlier versions of HTML, but in XHTML the characters < br are followed by a space and a forward slash before the closing angled bracket. 

 < p > When you want to start a new line you can use the line break element.

So, the next < br / > word will appear on a new line. < /p > 

 Creating Preformatted Text Using the < pre >Element 

 The HTML <pre> tag defines preformatted text.

Browsers naturally collapse multiple spaces or line breaks into a single space, but text inside a <pre> element is displayed exactly as it is written in the HTML source code. 

It preserves all spaces, tabs, and line breaks automatically. 

Content defaults to a fixed-width (monospaced) font, like Courier.

 The most common uses of the < pre > element are to represent computer source code. For example, 

 < pre > 

function testFunction(strText){

 alert (strText)

}

 < /pre > 

 The < hr / > Element 

 The < hr / > element creates a horizontal rule across the page. It is an empty element. 

 This is frequently used to separate distinct sections of a page where a new heading is not appropriate.



Introduction: Escape Characters | Comment

Character Entities (Escape Characters)

 ​Character entities are used when you need to display reserve characters that browsers would otherwise interpret as HTML code, or characters not readily available on a standard keyboard.

Character

Description

Numeric Entity

Named Entity

Common Use Case

"

Quotation mark

&#034;

&quot;

Used inside attribute values or text

&

Ampersand

&#038;

&amp;

Used to display bare ampersands in text

<

Less-than (left angle bracket)

&#060;

&lt;

Prevents browser from mistaking as tag start

>

Greater-than (right angle bracket)

&#062;

&gt;

Prevents browser from mistaking as tag end

Non-breaking space

&#160;

&nbsp;

Forces a space without line wrapping

©

Copyright symbol

&#169;

&copy;

Footer copyright notices


​Comment 

Syntax: Opens with <!-- and closes with -->.

​It's ignored by the browser and will not appear on the page.

​Comments are still visible to anyone viewing the web page's raw source code. 

Never place sensitive information (passwords, private keys, API credentials) inside HTML comments.

​Primary Uses:

​Documentation: Labeling major section starts/ends (e.g., <!-- Start Header -->).

​Developer Notes: Recording who modified code, dates, or layout reasons.

​Debugging: Temporarily disabling lines of code without deleting them.


Introduction: List Tag

 1. Unordered List (Bullet Points)

<ul>

  <li>HTML5 Syntax</li>

  <li>CSS Styling</li>

  <li>JavaScript Interactivity</li>

</ul>


2. Ordered List (Numbered Steps) 

<ol>

  <li>Open your text editor</li>

  <li>Write your HTML markup</li>

  <li>Save the file with a .html extension</li>

</ol>


3. Nested List (Sub-items inside a parent list item)

<ul>

  <li>Frontend Development

    <ul>

      <li>HTML</li>

      <li>CSS</li>

      <li>JavaScript</li>

    </ul>

  </li>

  <li>Backend Development

    <ul>

      <li>Node.js</li>

      <li>Python</li>

    </ul>

  </li>

</ul>

Direct Children Rule: An <ol> or <ul> can only contain <li> elements as direct children. You cannot put headings, paragraphs, or secondary lists directly inside a <ul> or <ol>.

Nesting Rule: To nest a list correctly, place the inner <ul> or <ol> inside an individual <li> tag, before that <li> is closed.

Correct: <li>Parent <ul><li>Child</li></ul> </li>

Incorrect: <li>Parent</li> <ul><li>Child</li></ul>


Description List 

<dl>

  <dt>Term</dt>

  <dd>Description or definition</dd>

</

dl>

​<dl> (Description List) — Main container element.

​<dt> (Description Term) — The key, term, or question (bold by default).

​<dd> (Description Details) — The value, definition, or answer (indented by default).


Tag List : Part 1

1. <address> : Contact info for document/article owner (Italicized, block-level default) 

<address>Wrox Press, 10475 Crosspoint Blvd, Indianapolis, IN 46256</address> 

2. <abbr> : Abbreviation with optional full-length hover title 

<p>I have a friend called <abbr title="Beverly">Bev</abbr>.</p>

4. <dfn> : Introducing a new or special term for the first time (Italicized)

<p>Mark up your documents using <dfn>XHTML</dfn>.</p>

5. <blockquote> & cite attribute : Extended quotes (Indented block)

<blockquote cite="http://www.w3.org/markup/">

  XHTML 1.0 is the W3C's first Recommendation for XHTML...

</blockquote>

<q> : Short inline quotations (Browsers automatically add quote marks) 

<p>As Dylan Thomas said, <q cite="http://example.com">Somebody's boring me. I think it's me</q>.</p>

6. <cite> : Citation source title (Italicized)

<p>This chapter is taken from <cite>Beginning Web Development</cite>.</p>

7. <code> : Computer code snippet (Monospaced font; escape < as &lt; and > as &gt;

<p><code>&lt;h1&gt;This is a primary heading&lt;/h1&gt;</code></p>

8. <kbd> : User keyboard input instructions (Monospaced font) -->

<p>Hold down <kbd>ctrl</kbd>, <kbd>alt</kbd>, and <kbd>delete</kbd> keys together.</p>

9. <var> : Variable/placeholder in programming contexts (Italicized) -->

<p><code>document.write("<var>user-name</var>")</code></p>

10. <samp> : Sample output from a computer program (Monospaced font) -->

<p><samp>This is the output from our test script.</samp></p>



Tag

Purpose

Default Styling

Modern Note

<address>

Contact information

Italic, new lines

Best reserved for article or site author details.

<abbr>

Abbreviations

Dashed underline (in some browsers)

Use title="" for full expansion.

<acronym>

Acronyms

Dashed underline

Obsolete in HTML5 — use <abbr> for both abbreviations and acronyms.

<dfn>

Defining instance of a term

Italic

Use only the first time a term is defined.

<blockquote>

Block-level quotes

Indented from margins

Use cite="" attribute for the source URL.

<q>

Inline quote

Quotation marks added around text

Use for short quotes inside paragraphs.

<cite>

Title of a work/citation source

Italic

HTML5 standard specifies this is for titles of works, not author names.

<code>

Computer code

Monospaced

Often wrapped in <pre> to preserve white space.

<kbd>

Keyboard or user input

Monospaced

Useful for instructional documentation.

<var>

Dynamic variable/placeholder

Italic

Works well inside <code> or <pre>.

<samp>

Computer output

Monospaced

Used to show what a computer program returns.