Free Astro tutorials for complete beginners.

Beginner's Guide to Astro

Lesson 6 of 7, about 15 minutes

Make it look good

Add one small file of styles so your text is easy to read on any screen. Then pick your own colours.

Tested on Astro 7.4

Right now your site is black text on white, edge to edge. A few lines of CSS will fix that for the whole site.

Step 1: Make a stylesheet

Inside src, make a folder called styles. Inside it, make global.css:

body {
  max-width: 40rem;
  margin-inline: auto;
  padding-inline: 1rem;
  font-family: system-ui, sans-serif;
  line-height: 1.6;
}

Here’s what each line does:

  • max-width keeps your text in a comfortable column.
  • margin-inline: auto centres that column.
  • padding-inline adds space on the sides, so text doesn’t touch the edge on phones.
  • font-family uses your computer’s own clean font.
  • line-height adds space between lines.

Step 2: Load it in your layout

Open src/layouts/Layout.astro. Add one line inside the frontmatter, under the Nav import:

---
import Nav from '../components/Nav.astro';
import '../styles/global.css';

const { title } = Astro.props;
---

Save.

Step 3: Pick your colours

Add this to the bottom of global.css. Then change the two colours to ones you like:

body {
  background: #fffdf7;
  color: #1f2430;
}

a {
  color: #0b57d0;
}

Those codes starting with # are colours. Search “colour picker” online, pick a colour, and copy its code.

The home page after step 3: a cream background, the menu and heading in a neat centred column, and blue links.

What you just did

You gave your site its own look, in one file that every page shares. Want to change the look later? Change this one file.

Finished lesson 6?

Mark it done to light its star, and we'll take you straight to lesson 7.

Try "blog", "deploy" or "EmDash".