Resources | Subject Notes | Information Communication Technology ICT
This section details how to specify font properties when creating websites using HTML. Understanding these properties allows for greater control over the visual presentation of text, enhancing readability and overall design.
The font-family
property specifies the font to be used for the text. It's crucial to include fallback fonts in case the primary font is not available on the user's system.
Example:
This text will be displayed in Arial. If Arial is not available, it will try Helvetica, and if that's not available, it will use a generic sans-serif font.
Important Note: Always list multiple font options separated by commas for better cross-browser compatibility.
The font-size
property controls the size of the text. It can be specified in various units:
px
: Pixels (absolute size)em
: Relative to the font size of the parent elementrem
: Relative to the font size of the root element (
)pt
: Points (absolute size)Example:
This text will be smaller than the default font size.
Note: Using relative units like em
and rem
is generally recommended for better responsiveness.
The color
property sets the colour of the text. Colours can be specified using various formats:
red
, blue
, green
)#FF0000
for red)rgb(255, 0, 0)
for red)hsl(0, 100%, 50%)
for red)Example:
This text will be blue.
The text-align
property determines the horizontal alignment of the text within its container.
Possible values are:
left
: Aligns text to the left.right
: Aligns text to the right.center
: Centers the text.justify
: Justifies the text, distributing it evenly between lines.Example:
This text will be centered.
The tag is used to display text in bold, and the
tag is used to display text in italics. These are inline elements.
Example:
This text is bold.
This text is italic.
Note: You can also use the font-weight
and font-style
CSS properties for bold and italic respectively, which are generally preferred for styling.
Property | Description | Example |
---|---|---|
Font Family | Specifies the font to be used. | ... |
Font Size | Controls the size of the text. | ... |
Font Colour | Sets the colour of the text. | ... |
Text Alignment | Determines the horizontal alignment of the text. | ... |
Bold | Displays text in bold. | This is bold |
Italic | Displays text in italics. | This is italic |