To change the font, we use the font-family
property.
h2 {
font-family: Garamond, sans-serif;
}
In the code above, sans-serif is a fall-back font if Garamond is unavailable.
Google Fonts offers thousands of open-source fonts for free use.
We can link a single font or multiple fonts with the font-weight and font-style properties.
To use Google Fonts, we need to link it in the <head>
section of the HTML.
<head>
<link rel="stylesheet" href="styles.css" />
<link
href="https://fonts.googleapis.com/css2?family=Playfair+Display&display=swap"
rel="stylesheet"
/>
</head>
and use it in CSS:
h2 {
font-family: "Playfair Display", serif;
}
We can style bold text in CSS with the font-weight
property. If we want to ensure that the text is not bold, we can set the font-weight
to normal.
p {
font-weight: normal;
}
p.thick {
font-weight: bold;
}
The font-weight property can also be assigned a number value to style text on a numeric scale ranging from 100 to 900. Values are multiples of 100.
font-style
property is mostly used to specify italic text. It also has a normal
value which is the default.
p {
font-style: italic;
}
We use word-spacing
to increase the spacing between words in the text. The default amount of space between words is usually 0.25em.
p {
word-spacing: 0.05em;
}
To increase the spacing between individual letters, we use letter-spacing
property in CSS.
h2 {
letter-spacing: 0.2em;
}
To modify line height, we use line-height
property. Line heights can take one of several values:
p {
letter-spacing: 10px;
}