Introduction to CSS


CSS (Cascading Style Sheets) is a fundamental technology used for styling web pages. It allows you to control the layout, colors, fonts, and overall visual presentation of your HTML content. In this post, we'll explore the basics of CSS.

What is CSS?

CSS is a stylesheet language that works alongside HTML to define how web content should be displayed. It provides a way to separate the structure (HTML) from the presentation (CSS) of a web page. This separation makes it easier to maintain and update web designs.

How Does CSS Work?

CSS works by selecting HTML elements and applying styling rules to them. These rules can be specified directly in HTML documents using the <style> element or, more commonly, in separate CSS files with a .css extension.

Here's an example of CSS code:

/* This is a CSS comment */
h1 {
    color: blue;
    font-size: 24px;
    text-align: center;

p {
    color: green;
    font-size: 16px;

In this example, we've defined styles for <h1> and <p> elements. The color, font-size, and text-align properties control the appearance of these elements.

CSS Selectors

Selectors are used to target specific HTML elements for styling. Here are some common CSS selectors:

  • Element Selector: Targets all instances of a specific HTML element, like h1, p, or a.
  • Class Selector: Targets elements with a specific class attribute, like .button or .highlight.
  • ID Selector: Targets a single element with a unique ID, like #header or #sidebar.
  • Descendant Selector: Targets elements that are descendants of a specific element, like ul li (targets all li elements inside a ul).
  • Pseudo-class Selector: Targets elements based on their state or position, like :hover or :first-child.

CSS Box Model

The CSS Box Model is a fundamental concept in web design. It defines how elements are displayed in boxes with content, padding, borders, and margins. Understanding the box model is crucial for controlling layout and spacing on web pages.

CSS Frameworks

CSS frameworks, like Bootstrap and Foundation, provide pre-designed styles and layout components to streamline web development. They offer a starting point for building responsive and visually appealing websites.


CSS is a powerful tool for web designers and developers. It allows you to control the appearance of web content and create stunning user interfaces. As you delve deeper into web development, mastering CSS is essential for creating beautiful and responsive websites.