CSS Selectors
Whereas HTML has tags, CSS has 'selectors'. Selectors are the names given to styles in internal and external style sheets. CSS HTML selectors are simply the names of HTML tags and are used to change the style of a specific tag:
td {
font-size: 0.8em;
color: green;
}
Properties
For each selector there are properties inside curly brackets, which simply take the form of words such as color
, font-weight
or background-color
.
Values
A value is given to the property following a colon ":" and semi-colons ";" separate the properties.
Ways to apply CSS to HTML
There are three different ways to apply CSS to HTML.
In-line
In-line styles can be assigned straight into the HTML tags using the style attribute:
<p style="color: blue">example</p>
Internal
Embedded, or internal styles are used for the whole page. Inside the head tags, the style tags surround all of the styles for the page.
...
<html>
<head>
<title>Example Page</title>
<style type="text/css">
h1 { color: green }
h2 { color: red }
</style>
...
External
External styles are used for the whole, multiple-page website. There is a separate CSS file:
...
<head>
<title>Example Page</title>
<link rel="stylesheet" type="text/css" href="web.css" />
...
The best-practice approach though is that the HTML should be a stand-alone, presentation free document, and so in-line styles should be avoided wherever possible.