In HTML, text formatting elements allow you to style and structure text content, while heading elements organize the document structure. Proper use of these elements improves readability, accessibility, and SEO (Search Engine Optimization).
HTML provides six levels of headings, from <h1>
(the most important) to <h6>
(the least important). Headings create a visual hierarchy and help search engines understand the structure of a webpage.
<h1>Main Heading</h1>
<h2>Subheading</h2>
<h3>Sub-subheading</h3>
<h4>Subsection</h4>
<h5>Sub-subsection</h5>
<h6>Lowest-level heading</h6>
<h1>
is typically used for the main title of a page.<h2>
through <h6>
are used for subheadings.<h1>
per page for SEO purposes, but multiple instances of the other headings are allowed.<h1>Welcome to My Blog</h1>
<p>This is the main content section.</p>
<h2>Introduction</h2>
<p>This section introduces the topic.</p>
<h3>Why Learn HTML?</h3>
<p>HTML is the foundation of web development.</p>
<h2>Conclusion</h2>
<p>Here we summarize the main points.</p>
HTML provides various elements for formatting text, such as bold, italic, underline, and more. These elements improve the appearance and structure of content.
<strong>
and <b>
<strong>
: Used to semantically emphasize important text, typically displayed as bold.<b>
: Used for stylistic boldness without semantic importance.<p>This is <strong>important</strong> text with emphasis.</p>
<p>This is <b>bold</b> text for styling.</p>
<em>
and <i>
<em>
: Adds emphasis to text and is displayed in italics.<i>
: Used for stylistic italicization without emphasis.<p>This is <em>emphasized</em> text with semantic importance.</p>
<p>This is <i>italicized</i> text for visual styling.</p>
<u>
<u>
: Underlines text. Traditionally, underlining is avoided in web design because it can be confused with links.<p>This is <u>underlined</u> text.</p>
<s>
and <del>
<s>
: Displays text with a line through it (strikethrough) but without indicating that it’s deleted.<del>
: Indicates that the text has been deleted.<p>This text is <s>struck through</s> for stylistic purposes.</p>
<p>This text is <del>deleted</del> from the document.</p>
<sub>
and <sup>
<sub>
: Displays text in subscript (lowered text).<sup>
: Displays text in superscript (raised text).<p>The chemical formula for water is H<sub>2</sub>O.</p>
<p>E = mc<sup>2</sup> is Einstein's famous equation.</p>
<code>
, <pre>
, and <kbd>
<code>
: Displays inline code snippets.<pre>
: Preserves whitespace and formatting (preformatted text).<kbd>
: Represents user input (keyboard).<p>To print "Hello, World!" in Python, use <code>print("Hello, World!")</code>.</p>
<pre>
def hello():
print("Hello, World!")
</pre>
<p>Press <kbd>Ctrl</kbd> + <kbd>C</kbd> to copy.</p>
print("Hello, World!")
.def hello():
print("Hello, World!")
HTML provides elements to handle quotations and citations, improving the presentation of quoted content.
<blockquote>
<blockquote>
: Used for long quotations. Typically indented by default in most browsers.<blockquote cite="https://www.example.com">
"The only limit to our realization of tomorrow is our doubts of today."
</blockquote>
“The only limit to our realization of tomorrow is our doubts of today.”
<q>
<q>
: Used for inline quotations, typically enclosed in quotation marks.<p>As Albert Einstein once said, <q>Imagination is more important than knowledge.</q></p>
<cite>
<cite>
: Used to indicate the title of a work, such as a book, movie, or website.<p><cite>The Great Gatsby</cite> is a novel by F. Scott Fitzgerald.</p>
HTML provides several ways to format text in lists, including ordered, unordered, and definition lists.
<ul>
An unordered list is used for items that do not need to be in a specific order. It typically displays with bullet points.
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<ol>
An ordered list is used for sequential or ranked items. It typically displays with numbers.
<ol>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ol>
<dl>
, <dt>
, <dd>
A definition list pairs terms with their definitions.
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>
Text alignment can be controlled using the style
attribute with the text-align
property in inline CSS. Common values include left
, right
, center
, and justify
.
<p style="text-align: left;">This text is aligned to the left.</p>
<p style="text-align: right;">This text is aligned to the right.</p>
<p style="text-align: center;">This text is centered.</p>
<p style="text-align: justify;">This text is justified, meaning that it is spread out so that the text on each line is evenly distributed.</p>
Special characters that are reserved in HTML can be displayed using entity codes.
<
: <
(less than)>
: >
(greater than)&
: &
(ampersand);`**: © (copyright symbol)
: Non-breaking space.<p>This is an example of <strong>bold</strong> text in code.</p>
<p>© 2024 My Website</p>
<p>10 000 items</p>
<strong>bold</strong>
text in code.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text Formatting and Headings</title>
</head>
<body>
<header>
<h1>Welcome to My Webpage</h1>
<p>Your guide to learning HTML text formatting and headings.</p>
</header>
<main>
<section>
<h2>Text Formatting Examples</h2>
<p>This is an example of <strong>bold</strong> text.</p>
<p>This is an example of <em>italic</em> text.</p>
<p>This is an example of <u>underlined</u> text.</p>
<p>This is an example of <s>strikethrough</s> text.</p>
</section>
<section>
<h2>Quotation Example</h2>
<blockquote cite="https://example.com">
"This is a long quote that is displayed in blockquote."
</blockquote>
</section>
<section>
<h2>Lists</h2>
<h3>Unordered List</h3>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<h3>Ordered List</h3>
<ol>
<li>First Item</li>
<li>Second Item</li>
<li>Third Item</li>
</ol>
</section>
</main>
<footer>
<p>© 2024 My Webpage</p>
</footer>
</body>
</html>
Next -> Images and Links
Back to Contents page click here