HTML Text Formatting
HTML (Hypertext Markup Language) provides various elements and attributes for formatting text and controlling how text is displayed on a web page. Here are some common HTML text formatting options:
Headings (
<h1>
to<h6>
): HTML offers six levels of headings, ranging from<h1>
(the highest level) to<h6>
(the lowest level). These elements are used to define the hierarchical structure of content, with<h1>
representing the main heading of the page and<h6>
representing subheadings.
This is a Heading 1
This is a Heading 2
This is a Heading 3
This is a Heading 4
This is a Heading 5
This is a Heading 6
<p>
): The <p>
element is used to define paragraphs of text. It creates a line break before and after the text enclosed within it, helping to separate content into logical blocks.
This is a paragraph of text.
3. Bold (<strong>
or <b>
) and Italics (<em>
or <i>
): You can use <strong>
or <b>
for bold text and <em>
or <i>
for italic text. <strong>
and <em>
carry semantic meaning, indicating the text’s importance or emphasis, while <b>
and <i>
are purely presentational.
This is important and emphasized text.
<u>
) and Strikethrough (<s>
or <del>
): <u>
is used for underlining text, while <s>
or <del>
is used for strikethrough text. <s>
and <del>
often indicate deleted or outdated content.
Underlined and strikethrough text.
<sup>
) and Subscript (<sub>
): These elements are used to format text as superscripts and subscripts, respectively. Superscripts are typically used for exponents, while subscripts are used for footnotes or chemical formulas.
x2 + y2 = r2
<code>
) and Keyboard Input (<kbd>
): <code>
is used to display inline code snippets, while <kbd>
is used to indicate keyboard input. These elements are often used in technical documentation.
To print a message to the console, use console.log('Hello, World!');
<cite>
) and Blockquotes (<blockquote>
): <cite>
is used to mark the title of a work (e.g., a book or a movie), while <blockquote>
is used for longer quotations, typically indented from the surrounding text.
The Great Gatsby by F. Scott Fitzgerald is a classic novel.
This is a longer quotation that requires a blockquote element.
Conclusion
These are some of the basic HTML text formatting elements and attributes. CSS (Cascading Style Sheets) can be used to further customize the appearance of text, allowing for precise control over fonts, colors, margins, and more.