CSS stands for Cascading Style Sheets.
CSS describes how HTML elements are to be displayed on screen, paper, or in other media.
CSS saves a lot of work. It can control the layout of multiple web pages all at once.
CSS can be added to HTML elements in 3 ways:
<style>element in the
The most common way to add CSS, is to keep the styles in separate CSS files. However, here we will use inline and internal styling, because this is easier to demonstrate, and easier for you to try it yourself.
Tip: You can learn much more about CSS in our CSS Tutorial.
An inline CSS is used to apply a unique style to a single HTML element.
An inline CSS uses the style attribute of an HTML element.
This example sets the text color of the
<h1> element to blue:
An internal CSS is used to define a style for a single HTML page.
An internal CSS is defined in the
<head> section of an HTML page, within a
An external style sheet is used to define the style for many HTML pages.
With an external style sheet, you can change the look of an entire web site, by changing one file!
To use an external style sheet, add a link to it in the
<head> section of the HTML page:
An 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.
Here is how the "styles.css" looks:
color property defines the text color to be used.
font-family property defines the font to be used.
font-size property defines the text size to be used.
border property defines a border around an HTML element:
padding property defines a padding (space) between the text and the border:
margin property defines a margin (space) outside the border:
To define a specific style for one special element, add an
id attribute to the element:
then define a style for the element with the specific id:
Note: The id of an element should be unique within a page, so the id selector is used to select one unique element!
To define a style for special types of elements, add a
class attribute to the element:
then define a style for the elements with the specific class:
External style sheets can be referenced with a full URL or with a path relative to the current web page.
This example uses a full URL to link to a style sheet:
This example links to a style sheet located in the html folder on the current web site:
This example links to a style sheet located in the same folder as the current page:
Required fields are marked *
Get all latest content delivered to your email free.