Styling text

Change the size, weight and alignment of text.

Your CSS is drawn by your own browser, inside this tab. Nothing to install.

Text size

font-size sets how big text is. px means pixels: 16px is the usual size of body text.

A value is a number and its unit with no space between them. 24 px is not valid and is ignored.

Example
p {
  font-size: 20px;
}

Your turn: a bigger heading

Set a size in pixels.

Practice task

Make the h1 40 pixels tall.

Your answer is run and checked in the lesson. Create a free account to try it.

Bold and italic

font-weight: bold makes text bold, and font-weight: normal removes it. Headings are bold unless you say otherwise.

font-style: italic slants text.

One rule can hold several declarations. Each ends with a semicolon.

Example
.intro {
  font-weight: bold;
  font-style: italic;
}

Lining text up

text-align moves text to the left, the center or the right of its element.

Note the spelling: CSS uses the American center and color.

Example
h1 {
  text-align: center;
}

Your turn: two declarations

Put two declarations in one rule.

Practice task

Make the h2 centred, and make it not bold.

Your answer is run and checked in the lesson. Create a free account to try it.