← Web basics: HTML, CSS and JavaScript
Fonts and text
font-family, font-size, font-weight, text-align and line-height.
Several properties shape text. font-family picks the typeface; give a list of choices ending with a general family like serif or sans-serif, because the visitor may not have your first choice. font-size sets the size, often in px or rem (1rem is the page's base size, usually 16px). font-weight makes text bold (bold or 700) or normal (400). font-style: italic slants it. text-align lines text up left, center or right. line-height sets the space between lines; about 1.5 makes paragraphs easy to read.
body {
font-family: Georgia, "Times New Roman", serif;
line-height: 1.5;
}
h1 {
font-family: Arial, Helvetica, sans-serif;
font-size: 2.5rem;
text-align: center;
}
.note {
font-style: italic;
}Body text uses Georgia if available, else Times New Roman, else any serif font. The h1 uses a sans-serif font at 2.5 times the base size, centered. Font names with spaces go in quotes.
Many text styles are inherited: set font-family once on body and every element inside uses it unless told otherwise.
Sizes in rem respect the visitor's own font-size setting, which matters for people who need larger text.