In addition to altering text size and boldness, HTML can be used to define and convey the meaning of information to browsers, as well as search engines and screen readers.
Knowing which HTML elements to use is key.
Defining Paragraphs
The element is used to define a paragraph. Usually browsers will present these as distinct paragraph boxes with space in between.
<p>This is the first paragraph.</p>
<p>This is the second paragraph.</p>
Consecutive spaces and line breaks are typically condensed to one space in HTML. However, simply including blank lines in the HTML source will not necessarily cause browsers to add extra space.
To add a line break, without beginning a new paragraph, the < br > element is used.
<p>
25 Oxford Street<br>
London<br>
United Kingdom
</p>
This is suitable for, for example, addresses and poems. Do not use several
elements to add space between paragraphs – CSS margin properties should be used for this instead.
Key Text HTML Elements
There are various HTML elements that can be used to alter both the style and/or meaning of text.
| HTML tag | Purpose | Default appearance |
|---|---|---|
<b> | Draws attention to text | Bold |
<strong> | Indicates strong importance | Bold |
<i> | Alternative voice or technical term | Italic |
<em> | Indicates stress emphasis | Italic |
<u> | Non-textual annotation | Underlined |
<mark> | Highlights relevant text | Highlighted |
<small> | Side comments or fine print | Smaller text |
<del> | Deleted content | |
<ins> | Inserted content | Inserted |
<sub> | Subscript | \(H_2O\) |
<sup> | Superscript | \(x^2\) |
Whilst the styles of and are typically the same, they differ semantically. The same is true of and .
You should utilise elements for their semantic value, in addition to (or even in preference to) their style.
Multiple Text Styling
HTML text styling elements can be combined.
<p>This is <strong><em>important information</em></strong>.</p>
<p>Previous price: <del>$100</del></p>
<p>New price: <strong>$75</strong></p>
Elements should always be closed in the opposite order to that in which they were opened. Poorly nested elements can lead to unexpected visual effects.
Using CSS To Style Paragraphs
Whilst HTML is used to describe the structure of information, CSS is used to define its style.
Below is an example of how CSS can be used to style, and add space around, paragraphs.
p {
font-family: Arial, sans-serif;
font-size: 18px;
line-height: 1.6;
color: #333333;
text-align: left;
margin-bottom: 20px;
}
The line-height property is used to set the space between lines of text. Margin bottom is used to add space after a paragraph.
Furthermore, specific classes can be applied to paragraphs so that they can be styled in different ways.
<p class="intro">
Welcome to our web development tutorial.
</p>
.intro {
font-size: 22px;
font-weight: 600;
letter-spacing: 0.5px;
}
This is a more versatile solution than adding style information to each paragraph.
Text Alignment
CSS allows text to be left, centre, right or fully justified. Each of these options will arrange text differently within the available space.
Left / Center / Right / Justify
CSS property: text-align: {alignment};
Generally, English text is pleasingly readable if left-aligned. Fully justified text has parallel left and right hand sides. However, this can cause inconsistent spacing between words, particularly on mobiles with limited screen width.
Maintaining Spacing and Coding
The element ensures that the exact spaces and line breaks from the HTML source code are reproduced.
To show computer coding, the element should also be used.
<pre><code>
function greet() {
return "Hello World";
}
</code></pre>
When showing HTML source code, characters that are not permitted in HTML need to be replaced with HTML entities (for example, < and >).
Failure to do this may cause browsers to attempt to execute the shown code, as they would with standard HTML.
Do Not Use Outdated Text Styling Elements
Previously, many websites utilised HTML elements including <font>, <center>, <big> and <strike> to style text.
However, these are no longer valid in current HTML.
Instead, use CSS properties such as font-size, font-family, color, text-align and text-decoration.
By distinguishing between the structural and stylistic aspects of information, HTML source code can be simplified. It can then be more easily maintained and a uniform style can be achieved across different devices.









