Posted by: Marcus Cyganiak | December 8, 2009

Tutorial: Applying CSS into HTML

CSS, which stands for Cascading Style Sheets, is a style sheet language that is used to describe the presentation semantics of a document written in a markup language. The most common application of CSS is to style web pages written in HTML and XHTML, in addition to any kind of XML document.

In-Line CSS

In-line styles are one of several ways you can put CSS to use. It is simply the CSS language being plugged straight into the HTML tags, using the style attribute.

Example:

In-Line CSS

Despite this form of applying CSS, the best practice is to keep any HTML documents as a stand-alone, presentation free document, thus in-line styles should be avoided as much as possible.

Internal CSS

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.

Example:

Internal CSS

This will make all the paragraphs in the page red and all the links blue.

Similar to in-line styles, HTML and CSS files should be kept separate.

External CSS

External styles are used for the whole, multiple-page website. There is a separate CSS file, which should something like this:

External CSS

If this file is saved as “stylesheet.css” then it can be linked to in the HTML document like this:

External CSS

To get the most from this tutorial, it would be a good idea to try out the code as I go along, so start a fresh new file with your text editor and save the blank document as “stylesheet.css” in the same directory as your HTML file.

Once you have saved the HTML file, it should then be linked to the CSS file, which is empty in this tutorial, so wouldn’t change a thing.

However, for further learning on CSS code, I would suggest visiting W3Schools.com.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.