Working with text in HTML is one of the first basics that beginners in web development need to master. In this lesson, you will learn how to add text to an HTML document, format it, align it, change its color and size, and use special effects like strikethrough or underline. Let’s start with the basics and move on to more complex examples.
1. Headings
The <h1>–<h6> tags are used for headings of different levels. The smaller the number in the tag, the larger the text:
<h1>Largest Heading</h1>
<h6>Smallest Heading</h6>
Headings are automatically bolded and start on a new line.
2. Aligning Headings:
The align attribute allows horizontal alignment of the text:
<h1 align="center">Centered Heading</h1>
3. Paragraphs
The <p> tag separates text into paragraphs:
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
align attribute can also be used to align text within a paragraph.4. Lines
To separate text, use the <hr> tag. It can be customized:
<hr width="50%" align="center" size="5" color="blue" noshade>
5. Text Highlighting
<i></i> or <em></em><b></b> or <strong></strong><u></u><s></s><sup></sup> and <sub></sub>
<p>This is the formula: H<sub>2</sub>O.</p>
6. Text Styles
Using the <font> tag (deprecated), you can change the text color, size, and font:
<font color="red" size="5" face="Arial">Red Text</font>
Let’s combine all the elements we’ve learned into one document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Text Formatting in HTML</title>
</head>
<body>
<h1 align="center">Text Formatting</h1>
<p align="justify">HTML is a markup language that allows you to create web pages.</p>
<p>Example of text highlighting: <strong>bold</strong>, <i>italic</i>, <u>underlined</u>.</p>
<hr width="50%" size="3">
<p align="right">Water formula: H<sub>2</sub>O.</p>
<p align="center"><font color="blue" size="4">Good luck with learning HTML!</font></p>
</body>
</html>
Knowledge Check: HTML Basics Test
63
HTML from Scratch: Adding Audio and Video to Your Website — For Beginners. Lesson #26
82
HTML from Scratch: The download Attribute in HTML5 (for downloading files). Lesson #25
149
HTML from Scratch: Commenting in HTML. Lesson #24
506
HTML from Scratch: The DOCTYPE Tag. Lesson #23
124
Leave a Reply