CSSbeginner 7 min
Set text colour, backgrounds, font family, size and weight.
How to write colours in a few formats and how to control the look of text.
Colour and typography do most of the work in making a page readable and pleasant. Readable contrast between text and background is also an accessibility need.
Colours can be written as:
tomato, royalblue.#ff6347 (red, green, blue in base 16).rgb(255, 99, 71).hsl(9, 100%, 64%) (hue, saturation, lightness), which is easiest to tweak by hand.Use color for text and background-color for the background.
Text properties you will use constantly:
font-family: the typeface, with fall-backs: font-family: Georgia, serif;font-size: 16px, or 1.25rem (relative to the root size).font-weight: 400 normal, 700 bold.line-height: space between lines, 1.6 is comfortable.text-align: left, center, right.body sets a serif font and comfortable line spacing. Children inherit these.h1 uses an hsl colour (blue) and a size in rem..card has a pale background, near-black text, bold weight and centred alignment.font-family lists a fall-back (serif) in case the first font is missing.Change the heading colour to #c2410c, then change the card's text-align to right.
color for backgrounds. Use background-color.# in hex colours.color for text, background-color for backgrounds.font-family, font-size, font-weight, line-height.Next: the box model, how every element takes up space.
<style>
body {
font-family: Georgia, serif;
line-height: 1.6;
}
h1 {
color: hsl(220, 80%, 45%);
font-size: 2.5rem;
}
.card {
background-color: #f1f5f9;
color: #0f172a;
padding: 16px;
font-weight: 700;
text-align: center;
}
</style>
<h1>Typography</h1>
<p class="card">Readable text on a soft background.</p>