CSS Tutorial

What is CSS?

CSS stands for Cascading Style Sheets. It's a language used to style web pages by controlling the appearance of HTML elements.

Practical Steps to Use CSS:

  • Linking a CSS File:
    • Create a CSS file with a .css extension.
    • Link it to your HTML file using the <link> tag:
<link rel="stylesheet" href="style.css">
  • Creating Style Rules:
    • Each style rule consists of a selector, a list of properties, and their values:
selector {
  property1: value;
  property2: value;
}
  • Selectors:
    • Selectors specify the HTML elements to style.
    • Examples:
      • body - styles the entire page
      • #header - styles the element with the id attribute "header"
      • .block - styles elements with the class attribute "block"
  • Properties:
    • Properties define the style attributes.
    • Examples:
      • color - sets the text color
      • font-size - sets the font size
      • background-color - sets the background color
  • Values:
    • Values specify the settings for properties.
    • Examples:
      • #000 - black color
      • 12px - 12 pixels font size
      • #f0f - light blue background color

Example:

<p>CSS stands for Cascading Style Sheets.</p>
p {
  color: red;
  font-weight: bold;
}

This will style all <p> elements on the web page by setting their text color to red and making them bold.