CSS Tutorial

CSS Syntax

CSS is a language used to style web pages. It allows you to control the appearance of text, images, and other elements on a web page.

Key Concepts:

  • Selectors: Target the elements you want to style
  • Properties: Specify the style you want to apply, such as color, font, or size
  • Values: The values for the properties, such as blue, Helvetica, or 12px
  • Semicolons: Terminate each style rule
  • Curly Braces: Group style rules for a selector

Simple CSS Example:

h1 {
  color: blue;
  font-family: Arial;
  font-size: 24px;
}

This rule targets all <h1> elements and sets their color to blue, font to Arial, and size to 24px.

Practical Steps:

  • Add a <style> element to your HTML: This is where you will write your CSS code.
  • Select the element you want to style: Use a selector, such as h1, p, or body.
  • Add curly braces: Open and close with {} to specify the style rules for that selector.
  • Define properties and values: Within the curly braces, add the properties and values, such as color: blue;.
  • Terminate with a semicolon: Each style rule must end with a semicolon ;.

Tips for Accessibility and Ease of Use:

  • Use color sparingly and avoid using only color to convey information.
  • Ensure there is sufficient contrast between text and background colors.
  • Specify font sizes in relative units, such as em or %, to allow users to adjust them.
  • Provide alternative text for images using the alt attribute.
  • Use headings and structure elements to improve navigation and organization.