Learn HTML and CSS: Text
Styling text
"My business card has everything in such a nice round typeface," says Gino. "And the prices are easy to read." Time to work on the letters themselves.
The typeface
font-family picks the typeface. You give a list with commas in between: the browser takes the first one the computer has.
Always end with a family: serif (with little feet), sans-serif (without) or monospace (every letter equally wide). One of those exists everywhere.
Set the typeface on body and all the text on the page inherits it.
body { font-family: Georgia, serif;}Size and weight
font-size sets how big the letters are, for example 40px. Normal text is 16 px.
font-weight sets how thick they are: normal or bold, or a number from 100 to 900. 400 is normal, 700 is bold.
Here the name is bigger and the subheadings are no longer bold: headings are by default.
h1 { font-size: 40px;}h2 { font-weight: normal;}Alignment and line height
text-align puts text on the left (left), in the centre (center) or on the right (right) of its block.
line-height sets the space between lines. A number without a unit, like 1.6, means 1.6 times the font size.
Slightly roomier lines are much nicer to read, especially on a phone.
header { text-align: center;}p { line-height: 1.6;}Try it yourself
Make the price list (ul) easier to read: typeface Verdana, sans-serif, letters of 18px and a line height of 1.6.
/* Your CSS goes here. */<!DOCTYPE html><html lang="en"> <head> <title>Snip & Curl hair salon</title> <link rel="stylesheet" href="basis.css"> <link rel="stylesheet" href="style.css"> </head> <body> <header> <h1 id="name">Snip & Curl</h1> <p class="slogan">Hair salon in the heart of Leeds</p> </header> <main> <h2>Our prices</h2> <ul class="price-list"> <li><span class="service">Haircut</span> <span class="price">£28</span></li> <li><span class="service">Wash and blow-dry</span> <span class="price">£22</span></li> <li><span class="service">Colouring</span> <span class="price">£55</span></li> </ul> <section id="booking"> <h2>Book an appointment</h2> <p class="info">Give us a call or just pop in.</p> <a class="button" href="tel:+441134960000">Call us</a> </section> </main> <footer> <p>8 Kirkgate, Leeds</p> </footer> </body></html>body { margin: 0; padding: 0 16px;}Ready for more?
The full lesson has 5 exercises, from easy to challenging, with hints, points and a streak you can build.
Start the lesson