How CSS Works

CSS Tutorial

How CSS Works

CSS, or Cascading Style Sheets, is like a magic wand that you use to make your web pages beautiful and organized. This is the device that controls everything on your webpage -the text, pictures, buttons, and more. Think of it as a stylist that determines the colors, fonts, and layouts of the “outfit” of your website. Let’s break it down in an easy, friendly way.

1. CSS Specifies How Your Page Should look.

Imagine that your webpage is just a plain document with words and pictures, such as some sketch. This is the one that performs HTML (hypertext markup language) – it creates structure, such as paragraphs, headings or images. But without CSS, it looks boring, like a black and white drawing.

2. CSS steps to add style:

  • Want a bright blue background? CSS can do this.
  • Need your titles in bold, red, Italic text? CSS has covered you.
  • Want buttons to look smooth and modern? CSS is like this. 

It prefers to give a makeover to your webpage, the system of color, size and everything.

3. CSS Uses Rules to Style Things

CSS works with the aid of growing policies that tell the browser the way to display one of a kind elements of your website. Each rule is like a little preparation that asserts, “Hey, make this part appear like this.”

A CSS rule has the foremost elements:

  • Selector: These choices a part of the website you need to style. For instance, h1 selects all degree-one headings, or .Button selects anything with the class “button.”
  • Declaration: This says what style to apply. For example, color: blue; makes the text blue, or background-color: yellow; sets a yellow background.

				
					h1 {
    color: blue;
    font-size: 36px;
}

<!--This rule says, “Make all <h1> headings blue and set their font size to 36 pixels.”-->
				
			

4. How CSS is connected to HTML

CSS needs to know which parts of your web page you are going to style, and it does this by linking to your HTML. There are three main ways to add CSS to your web page:

  • Inline CSS: You add styles directly to an HTML tag using the style attribute.

For example:

<p style=”color: green;”>This text is green!</p>

This is fast, but messy for big projects.

  • Internal CSS: You put CSS in a <style> code in the <Head> section of your HTML file.

For example:

				
					<head><style>
p { color: green; }
</style>
</head>
				
			

This is good for small pages.

  • External CSS: You write CSS in a separate file (as styles.css) and connect it to the HTML a <link> tag:
				
					<head>
    <link rel="stylesheet" href="styles.css">
</head>
				
			

This is the best approach for larger websites, as it keeps things organized.

CSS Demo - One Page, Multiple Styles

CSS Demo - Multiple Styles

This page demonstrates how CSS can change the look and feel of a webpage. Click the buttons below to switch styles!

Try It Yourself

Share with friends

Leave a comment

Your email address will not be published. Required fields are marked *