Text and Formatting in HTML (Live Playground)
Text is a fundamental part of any web page, and HTML provides several elements for organizing and formatting text content. In this tutorial, you will learn how to use essential HTML elements for text and formatting, including headings, paragraphs, line breaks, and basic text styling.
HTML headings are used to structure your content and make it more readable. There are six levels of headings, ranging from
<h1> (the largest and most important) to
<h6> (the smallest and least important). Headings should be used in a hierarchical manner, with
<h1> being the main heading of your page, followed by
<h2> for subsections, and so on.
<!-- ... -->
<p> element is used to define a paragraph of text. Browsers automatically add some space (margin) before and after each paragraph.
<p>This is a paragraph of text.</p>
<p>Here is another paragraph of text.</p>
<br> element is used to insert a line break within a block of text, such as within a paragraph or heading. It is a self-closing tag, which means it does not require a closing tag.
<p>This is a line of text.<br />Here is a new line within the same paragraph.</p>
Basic Text Styling
HTML provides several elements for basic text styling, such as bold, italic, and underlined text. Here are some examples:
- Bold: The
<strong>element is used to define important text that should be bold.
<p>This is a <strong>bold</strong> word in a paragraph.</p>
- Italic: The
<em>element is used to define emphasized text that should be italic.
<p>This is an <em>italicized</em> word in a paragraph.</p>
- Underlined: The
<u>element is used to define underlined text. However, using CSS for underlining is recommended as the
<u>tag is often associated with deprecated elements.
<p>This is an <u>underlined</u> word in a paragraph.</p>
- Superscript and Subscript: The
<sub>elements are used to define superscript and subscript text, respectively.
<p>This is a word with a <sup>superscript</sup>.</p>
<p>This is a word with a <sub>subscript</sub>.</p>
Using essential HTML elements for text and formatting is crucial for creating well-structured and visually appealing web pages. In this tutorial, you learned how to use headings, paragraphs, line breaks, and basic text styling elements effectively in your web projects.
As you continue to explore HTML, you will encounter more advanced elements and techniques for formatting and styling text, such as using CSS for greater control over your text's appearance. Keep practicing and experimenting with different HTML elements to create engaging and accessible web pages.