Cascading Style Sheets — or CSS — is the first technology you should start
learning after HTML. While HTML is used to define the structure and semantics
of your content, CSS is used to style it and lay it out.
You can do all kinds of things with CSS. So for example, you might have a
nested span element inside of the paragraph. You could then use this to
influence a single word.
1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html><html>
<head>
<title>Webpage</title>
<linkrel="stylesheet"href="main.css" />
</head>
<body>
<h1>Main heading</h1>
<p>This is a <span>paragraph</span></p>
</body>
</html>
1
2
3
p>span {
color: blue;
}
Note the following:
The new span on line 9 of the HTML
The selector is now p > span, this describes a span inside a p
The style applied is changing the color to blue, instead of the font
Another way to apply style is based on attributes. For example you can add
class attributes to the HTML, and then reference this via the stylesheet.
For example, here is a paragraph with a blue class:
1
<pclass="blue">This is a paragraph</p>
And here is some css that applies style to that particular paragraph:
1
2
3
4
5
6
7
h1 {
padding: 1;
}
p.blue {
color: blue;
}
Note: You can ignore the h1 style above, it’s just there to demonstrate how
you can have multiple styles inside a single file (separated by whitespace)