A CSS (cascading style sheet) file allows you to separate your web sites HTML content from it’s style. As always you use your HTML file to arrange the content, but all of the presentation (fonts, colors, background, borders, text formatting, link effects & so on…) are accomplished within a CSS.
- CSS stands for Cascading Style Sheets
- Styles define how to display HTML elements
- Styles were added to HTML 4.0 to solve a problem
- External Style Sheets can save a lot of work
- External Style Sheets are stored in CSS files
Styles define how to display HTML elements Styles were added to HTML 4.0 to solve a problem External Style Sheets can save a lot of work External Style Sheets are stored in CSS files
How to use the CSS?
We can use Three Ways to Insert CSS
First we will explore the internal method. This way you are simply placing the CSS code within the tags of each HTML file you want to style with the CSS. example below.
<head> <title><title> <style type="text/css"> CSS Content Goes Here </style> </head> <body>
With this method each (X)HTML file contains the CSS code needed to style the page. Meaning that any changes you want to make to one page, will have to be made to all. This method can be good if you need to style only one page, or if you want different pages to have varying styles.
<link rel="stylesheet" type="text/css" href="Path To stylesheet.css" />
Or you can also use the @import method as shown below
<style type="text/css">@import url(Path To stylesheet.css)</style>
Either of these methods are achieved by placing one or the other in the head section as shown in example below.
<head> <title><title> <link rel="stylesheet" type="text/css"href="style.css" /> </head> <body> or <head> <title><title> <style type="text/css"> @import url(Path To stylesheet.css) </style> </head>
An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly!
To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:
<p style="color: #ff0000;">Some red text</p>