Published by Patrick Mutisya · 14 days ago
Be able to specify the font properties including font family, size, colour, alignment, bold and italic.
The following CSS properties control the appearance of text on a web page.
Font properties are normally set using a <style> block or an external stylesheet, but they can also be applied directly with the style attribute on individual elements.
Example of inline styling (for illustration only):
<p style="font-family: Arial; font-size: 14px; color: #333333; text-align: justify; font-weight: bold; font-style: italic;">
This paragraph uses all six font properties.
</p>
| Generic family | Typical fonts | Typical use |
|---|---|---|
| serif | Times New Roman, Georgia | Print‑like documents, formal reports |
| sans‑serif | Arial, Verdana, Helvetica | Web pages, headings, modern layouts |
| monospace | Courier New, Consolas | Code snippets, tabular data |
| cursive | Comic Sans MS, Brush Script | Informal notes, decorative text |
| fantasy | Impact, Papyrus | Special effects, titles |
Font size should be readable on the intended device. Common practice:
When selecting a text colour, ensure sufficient contrast with the background. The WCAG guideline recommends a contrast ratio of at least 4.5:1 for normal text.
Bold and italic can be applied via CSS or by using semantic HTML tags:
<strong> – indicates strong importance; browsers render it bold.<b> – visual bold without semantic meaning.<em> – indicates emphasis; browsers render it italic.<i> – visual italic without semantic meaning.<!DOCTYPE html>
<html>
<head>
<style>
.highlight {
font-family: "Verdana", sans-serif;
font-size: 18px;
color: #0066CC;
text-align: center;
font-weight: bold;
font-style: italic;
}
</style>
</head>
<body>
<p class="highlight">Important announcement</p>
</body>
</html>