[!] [=title "Week 4: Style"] [=content-]

We've done some pretty cool stuff with HTML so far, but there's still a barrier between that and all of the wonderful websites you know. We need styles!

Styling on the internet is done with something called Cascading Style Sheets - CSS. CSS is a deceptively simple language responsible for color, size, shape, font, layout, etc - all of the things that make webpages beautiful!

The core of CSS is properties and selectors. All properties have a name, a colon, a value, and a semicolon. For instance, a property to make text red would look like:

color: red;

CSS can be written in a lot of places. The easiest way is inline properties - you put your CSS properties in the style HTML attribute, and they apply automagically! For instance:

<p style="color: red;">Red Text</p>

This will set the color of that one specific p element to red. It will not set the color of any other elements; for that, you need a selector! A selector looks like this:

p {
	color: red;
}

Note the tag name p, the opening brace {, the properties (each on their own line!), and the closing brace }. CSS is much pickier than HTML, and if you write this wrong, it could break the entire stylesheet!

The effect is that this selects every p element on the page and sets its color to red.

You can't just throw this anywhere! It needs to go in one of a few specific places. The easiest place is a <style> tag. For instance:

<style>
p {
	color: red;
}
</style>

This is considered metadata, so it must go in your <head>.

You can (and should!) also store your CSS in an external file with the ".css" extension - e.g., "style.css" is common. This can then be referenced in your HTML document's header like this:

<link rel="stylesheet" href="style.css" />

Look familiar? This is another use of the elusive link tag!

There are very, very many CSS properties. I can't hope to exhaustively list them (and indeed I don't know all of them!) but here are a few common ones:

[/] [#template.html]