CSS: Styling Your Web Pages

CSS Styling

What is CSS?

CSS stands for Cascading Style Sheets. It's the language we use to style an HTML document. CSS describes how HTML elements should be displayed.

How to Add CSS

There are three ways to insert CSS:

  1. Inline: Using the style attribute inside HTML elements.
  2. Internal: Using a <style> element in the <head> section.
  3. External: Using an external CSS file. This is the recommended way.

Basic CSS Syntax

A CSS rule set contains a selector and a declaration block:

                    
            selector {
              property: value;
            }
                    
                

Example:

                    
            h1 {
              color: blue;
              font-size: 3em;
            }
                    
                

Common CSS Properties

  • color: Sets the color of the text.
  • font-size: Sets the size of the text.
  • background-color: Sets the background color of an element.
  • margin: Sets the margin around an element.
  • padding: Sets the padding inside an element.