Skip to main content

Text and Formatting in HTML (Live Playground)

Introduction

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.

Headings

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.

HTML
<h1>Main Heading</h1>
<h2>Subheading</h2>
<h3>Sub-subheading</h3>
<!-- ... -->
<h6>Smallest Heading</h6>
Live Playground, Try it Yourself

Paragraphs

The <p> element is used to define a paragraph of text. Browsers automatically add some space (margin) before and after each paragraph.

HTML
<p>This is a paragraph of text.</p>
<p>Here is another paragraph of text.</p>
Live Playground, Try it Yourself

Line Breaks

The <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.

HTML
<p>This is a line of text.<br />Here is a new line within the same paragraph.</p>
Live Playground, Try it Yourself

Basic Text Styling

HTML provides several elements for basic text styling, such as bold, italic, and underlined text. Here are some examples:

  1. Bold: The <strong> element is used to define important text that should be bold.
HTML
<p>This is a <strong>bold</strong> word in a paragraph.</p>
  1. Italic: The <em> element is used to define emphasized text that should be italic.
HTML
<p>This is an <em>italicized</em> word in a paragraph.</p>
  1. 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.
HTML
<p>This is an <u>underlined</u> word in a paragraph.</p>
  1. Superscript and Subscript: The <sup> and <sub> elements are used to define superscript and subscript text, respectively.
HTML
<p>This is a word with a <sup>superscript</sup>.</p>
<p>This is a word with a <sub>subscript</sub>.</p>
Live Playground, Try it Yourself

Conclusion

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.