HTML Text Formatting
<p>
The <p> element defines a paragraph. Browsers automatically add margin before and after each paragraph. A paragraph is composed of two or more sentences.
Code
<!--Paragraph Example--> <p> This is a sentence. A paragraph is composed of two or more sentences. So now, I am a pragraph! Wow! </p>
Output
This is a sentence. A paragraph is composed of two or more sentences. So now, I am a pragraph! Wow!
<h1> through <h6>
HTML defines six heading levels. <h1> carries the most weight and is used for main titles; <h6> is the smallest. Proper heading hierarchy improves both accessibility and SEO.
Code
<!--Headings Example--> <h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6>
Output
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
<i>, <dfn>, <cite>
All three tags render text in italic but have different semantic meanings: <i> is used for stylistic italics, <dfn> marks a term being defined, and <cite> references a creative work (book, film, etc.).
Code
<i>This is a sentence.</i> <!-- stylistic italic --> <dfn>This is a sentence.</dfn> <!-- definition term --> <cite>This is a sentence.</cite><!-- citation/work title --> <i>A phrase.</i> <dfn>A phrase.</dfn> <cite>A phrase.</cite>
Output
This is a sentence.
This is a sentence.
A phrase.
A phrase.
A phrase.
Notice the color difference: <dfn> renders in purple and <cite> in blue in this styled preview, highlighting their distinct semantic roles even though they visually appear as italic.
<mark>
The <mark> element highlights text, similar to using a highlighter on paper. It is used to mark text of special interest or relevance in a given context.
Code
<mark>This text is highlighted.</mark>
Output
<sup> & <sub>
<sup> renders text as superscript (raised above baseline), commonly used for exponents or ordinals like X2. <sub> renders text as subscript (below baseline), used in chemical formulas like H2O.
Code
<sup>This is a superscript text.</sup> <sub>This is a subscript text.</sub>
Output
<code>, <kbd>, <samp>
All three render in a monospace font but serve different purposes: <code> represents a fragment of computer code, <kbd> represents keyboard input, and <samp> represents sample output from a program.
Code
<code>This is a sentence.</code> <kbd>This is a sentence.</kbd> <samp>This is a sentence.</samp> <code>A phrase.</code> <kbd>A phrase.</kbd> <samp>A phrase.</samp>
Output
This is a sentence.
This is a sentence.
This is a sentence.
A phrase. A phrase. A phrase.
<u> & <ins>
<u> renders text with an underline for stylistic purposes (e.g., proper names in Chinese). <ins> marks text that has been inserted into the document — it also underlines but carries semantic meaning for document revision tracking.
Code
<u>This text is underlined.</u> <br> <ins>This line is inserted.</ins>
Output
This line is inserted.
— Non-breaking Space for Indentation
The HTML entity inserts a non-breaking space character. Unlike a normal space, it will not collapse or wrap. It can be chained together to add indentation inside a paragraph.
Code
<p> This sentence is indented.</p>
Output
This sentence is indented.
<div> Element with CSS Class
The <div> element is a generic block-level container. When combined with a CSS class attribute, it can be targeted with style rules. Below, the .myDiv class applies a red background and black outset border.
.myDiv { border: 5px outset black; background-color: red; text-align: center; }
<div class="myDiv"> <h2>Heading in div</h2> <p>Some text in a div.</p> </div>
Output
This is a heading in a div element
This is some text in a div element.
<blockquote>
The <blockquote> element defines a section quoted from another source. Browsers typically indent blockquotes. The cite attribute specifies the URL of the source.
Code
<blockquote cite="http://www.worldwildlife.org/..."> For 50 years, WWF has been protecting the future of nature... </blockquote>
Output
For 50 years, WWF has been protecting the future of nature. The world's leading conservation organization, WWF works in 100 countries and is supported by 1.2 million members in the United States and close to 5 million globally.
<pre> vs <p>
The <pre> element displays text exactly as written in the HTML — preserving spaces, line breaks, and indentation. A <p> collapses all whitespace into a single space.
You ask about the cows, wearin' my sweater It's somethin' 'bout the weather that makes them lie down The only time I feel I might get better is when we are together, oh, together
Live Output — <pre>
You ask about the cows, wearin' my sweater It's somethin' 'bout the weather that makes them lie down The only time I feel I might get better is when we are together, oh, together
CSS Selectors (via style.css)
#id
The CSS id selector targets a single unique element using the # prefix. An id must be unique on the page. Below, #para1 styles the paragraph with blue centered text.
#para1 { text-align: center; color: blue; }
<p>An example for id Selector</p> <p id="para1"> This paragraph is an example for id Selector. </p>
Output
An example for id Selector
This paragraph is an example for id Selector.
.class
The CSS class selector targets any element with a matching class attribute using the . prefix. Unlike id, the same class can be applied to multiple elements. Here, .right right-aligns and colors the text red.
.right { text-align: right; color: red; }
<p class="right"> Styled using a class selector. </p> <h2 class="right"> Also using the same class. </h2>
Output
An example for class Selector
This paragraph is styled using a class selector.
h3, h4
The CSS grouping selector applies the same rules to multiple selectors at once, separated by commas. This reduces code repetition. Here, both h3 and h4 are centered and colored green.
h3, h4 { text-align: center; color: green; }
<h3> Styled using a group selector. </h3> <h4> Also using the same group. </h4>
Output
An example for group Selector