There are three methods that can be used to manipulate the design of your page using CSS: Linking the CSS, embedding the CSS or writing the CSS inline (within an HTML element). Each has its own application and advantages.
CSS follows conventions that are both similar to and unique from HTML. While both specify the appearance of elements with brackets and certain syntax, CSS has two unique elements: the selector and the declaration.

Many declarations and values may be associated with one selector and sometimes multiple values are possible with a single declaration. Thus, a single selector may contain several lines of code, as we’ll see in a moment.
Sometimes an individual tag needs to look different than any other instance of the tag on the page or entire site. This requires that we specify the presentation within the HTML of the individual element.
Example (Always appears within an HTML tag)
<h1 style=“font-size: 24px; color: gray;”>My headline</h1>
Certain circumstances demand that a single page look unique from other pages and therefore uses unique styles. This is when we embed styles to that page only by writing the CSS in the head of the HTML document instead of linking the CSS. Here are the basics of embedded styles.
Example (Always appears after <head> and before </head>)
<head>
<title>John Doe: Home page</title>
<meta charset="utf-8">
<style>
h1 {font-size: 24px;}
</style>
</head>
The most widely applicable CSS within a site, linked styles are incorporated by linking a separate document with .css extension that is linked to all HTML files in the site.
Example (HTML link)
<!DOCTYPE html>
<html>
<head>
<title>John Doe: Homepage</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>Example (within styles.css)
h1 {font-size: 24px; font-variant: small-caps;}
Most of the CSS we write will be done in a unique CSS document that is linked to our site pages. And like beginning a new HTML file, a new CSS file created with a blank text editor file. Using TextWrangler (or Notepad at home) hit “File > New”.
With your blank document, type the following:
body {
font-family: georgia, “times new roman”, serif;
}
What have you just composed? Simple put, you are telling the browser to apply a black background to the body of the HTML document (which is the entire browser window) and use an available serif font from the list provided here. We will address fonts more in a moment but let’s save this document and link it to our HTML file(s).
Just as with an HTML document, we first select “File>Save As” from our menu and navigate to the appropriate directory. For our purposes, this requires our returning to the folder that contains your first exercise.
With this directory selected, save the file as “styles.css”. The file name does not matter, so long as there are no spaces and it contains a .css extension. You may want to name it “firststyles.css” for your own reference. Remember the file name because we will be referring to it in a moment.
Now that we have a CSS file in the same folder as our HTML files, we have to link the various files. As noted earlier, this is accomplished in the <head> section of the HTML:
<head>
<title>John Doe: Home page</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
This line of code simply tells the browser to connect to a stylesheet named “styles.css”. If you used another file name, be sure to substitute it here. Save your HTML file by selecting “File > Save”.
Open the HTML file in the browser window. Your text should change to a Georgia font from the default browser font (usually “Times New Roman”).
Now click on your internal website links. Notice the font has reverted to the standard browser font instead of Georgia. This is because we have not yet linked the stylesheet to the other pages. These are your next steps before continuing:
With the last exercise, we established a font family for the entire pages of our earlier site by redefining the body tag. However, the body tag is not unique in this regard: nearly every HTML tag can be manipulated with CSS by simply using it as our selector and declaring appropriate values.
Let’s consider the next tag we experimented with in HTML, the largest header tag <h1> by following these steps:
h1 {
font-size: 200px;
}
h1 {
font-size: 28px;
letter-spacing: 3px;
font-variant: small-caps;
}
Refresh your page and examine the changes. Your header text should now be all caps (done with font-variant) your text should be slightly spaced apart (done with letter-spacing) and it should be red (done with color).
Letter-spacing and font-variant should be used sparingly and usually only with headers.
p {
font-size: 11px;
line-height: 16px;
}
Like before, save the document and refresh your page. The differences of text size (font-size), color (color) and leading (line-height) should be immediately evident in your paragraph text.
Matthew Blake Department of Journalism CSU-Chico
mdblake@csuchico.edu (530) 898-3608