Web Programming: Lecture 3: CSS Introduction
Web Programming: Lecture 3: CSS Introduction
• The following example sets the text color of ALL the <h1> elements
(on that page) to blue, and the text color of ALL the <p> elements
to red. In addition, the page will be displayed with a "powderblue"
background color:
Internal CSS
<!DOCTYPE html>
<html>
<head>
<style>
body {background-color: powderblue;}
h1 {color: blue;}
p {color: red;}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External CSS
• An external style sheet is used to define the style for many HTML
pages.
• The external style sheet can be written in any text editor. The file
must not contain any HTML code, and must be saved with a .css
extension.
External CSS
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
External CSS
• Here is what the "styles.css" file looks like:
body {
background-color: powderblue;
}
h1 {
color: blue;
}
p{
color: red;
}