Sunday, June 21, 2026

What is CSS? Complete Beginner’s Guide to CSS (Selectors, Properties & Examples)


Introduction

CSS, which stands for Cascading Style Sheets, is a stylesheet language used to control the presentation and design of HTML documents. It allows developers to separate content from design, making websites easier to maintain, update, and scale.

When you visit a website, the colors, fonts, layouts, animations, and overall visual appearance you see are primarily created using CSS. Without CSS, web pages would appear as plain text and basic HTML elements with little to no visual appeal.


What is CSS, and why is it used?

CSS (Cascading Style Sheets) is a stylesheet language used to define the visual appearance and layout of web pages. It works alongside HTML to control how elements such as text, images, buttons, forms, and sections are displayed in a browser.

HTML provides the structure and content of a webpage, while CSS is responsible for its design and presentation. Using CSS, developers can change colors, fonts, spacing, alignment, backgrounds, animations, and responsive layouts without modifying the HTML content itself.

For example, HTML can create a heading:

<h1>Welcome to My Website</h1>

By default, the heading appears with the browser's standard styling. CSS can then be used to customize its appearance:

h1 {
    color: blue;
    font-size: 40px;
    text-align: center;
}

As a result, the heading becomes more visually appealing and aligned with the website's design.


Why is it used?

CSS is used because it makes websites attractive, user-friendly, and easier to maintain. Instead of styling each HTML element individually, developers can manage the entire website's design from one or more CSS files.

Some key reasons for using CSS include:

1. Improves Website Appearance

    CSS allows developers to add colors, fonts, backgrounds, borders, shadows, and other visual effects that enhance a website's overall look.

2. Creates Responsive Designs

    Modern users access websites from desktops, tablets, and smartphones. CSS enables responsive web design, ensuring websites adapt to different screen sizes and devices.

3. Separates Content from Design

    By keeping HTML for content and CSS for styling, websites become more organized, easier to maintain, and easier to update.

4. Ensures Consistent Design

    A single CSS file can control the appearance of multiple web pages, helping maintain a consistent design across an entire website.

5. Enhances User Experience

    Proper spacing, typography, layouts, and interactive effects created with CSS improve readability and make websites easier to navigate.


Types of CSS?

CSS can be applied to an HTML document in three different ways. These methods are known as the Types of CSS. Each type serves a specific purpose and can be used depending on the project's requirements.

  1. Inline CSS

            Inline CSS is written directly inside an HTML element using the style attribute. It affects only the specific element where it is applied.
            
Example
   <h1 style="color: blue; font-size: 36px;">
      Welcome to My Website
   </h1>

  1. Internal CSS

            Internal CSS is written inside a <style> tag within the <head> section of an HTML document. The styles apply only to that specific webpage.

Example

<!DOCTYPE html>
<html>
<head>
    <style>
        h1 {
            color: blue;
            text-align: center;
        }

        p {
            font-size: 18px;
        }
    </style>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>This is a paragraph.</p>
</body>
</html>

  1. External CSS

            External CSS stores all styles in a separate .css file and links it to the HTML document using the <link> tag.

HTML File

<head>
    <link rel="stylesheet" href="style.css">
</head>

CSS File (style.css)

h1 {
    color: blue;
    text-align: center;
}

p {
    font-size: 18px;
}


The History of CSS: How the Web Learned to Look Good

Today, CSS is an essential part of web development, but the early web looked very different. In the early 1990s, websites were built entirely with HTML, which was designed to structure content rather than style it. Web pages were mostly plain text with basic headings, lists, and links. There was no easy way to control colors, fonts, layouts, or spacing.

As the web grew, developers began demanding better ways to design and customize websites. This need eventually led to the creation of CSS (Cascading Style Sheets).

The Birth of CSS (1994)

The idea for CSS was first proposed in 1994 by Håkon Wium Lie, a Norwegian web pioneer who was working at CERN, the same organization where the World Wide Web was originally created.

Lie believed that web pages should have a separate language dedicated to styling and presentation. He proposed the concept of "Cascading Style Sheets," allowing developers to define styles independently from HTML content.

Later, Bert Bos joined the project and helped refine the specification.


Why is it Called "Cascading" Style Sheets?

Many developers use CSS every day without knowing why it is called "Cascading."

The word "Cascading" refers to the way CSS resolves conflicts when multiple style rules apply to the same element. The browser follows a set of priority rules to determine which style to use.

This cascading mechanism became one of CSS's most powerful features and remains a core concept today.


CSS Level 1 (CSS1) – 1996

In December 1996, the World Wide Web Consortium (W3C) officially released CSS Level 1 (CSS1).

CSS1 introduced basic styling features such as:

  • Fonts
  • Colors
  • Text formatting
  • Margins
  • Padding
  • Borders
  • Background properties

Although limited by modern standards, CSS1 marked the beginning of a new era in web design.

The Browser Wars and CSS Adoption

During the late 1990s, web browsers were competing fiercely for market share. The main competitors were:

  • Netscape Navigator
  • Internet Explorer

Each browser implemented CSS differently, creating major compatibility problems. A design that looked correct in one browser might break in another.

Developers often had to write separate code for different browsers, making web development frustrating and time-consuming.


CSS2 – 1998

To address growing design needs, W3C released CSS2 in 1998.

CSS2 introduced many important features, including:

  • Positioning
  • Z-index layering
  • Media types
  • Advanced selectors
  • Support for different devices
  • Better layout control

These additions allowed developers to create more sophisticated websites than ever before.


The Long Journey to CSS3

Unlike CSS1 and CSS2, CSS3 was not released as a single specification.

Instead, the W3C divided CSS into separate modules, allowing features to be developed independently. This modular approach accelerated innovation and made it easier to introduce new capabilities.

Some famous CSS3 modules include:

  • Animations
  • Transitions
  • Flexbox
  • Grid Layout
  • Media Queries
  • Border Radius
  • Box Shadow
  • Transformations

These features transformed CSS from a simple styling language into a powerful layout and design system.


The Mobile Revolution and Responsive Design

The rise of smartphones in the late 2000s changed web development forever.

Developers needed websites that could adapt to different screen sizes. CSS answered this challenge through Media Queries, which allowed layouts to change dynamically based on device characteristics.

This innovation led to Responsive Web Design, now considered a standard practice in modern web development.


Modern CSS

Today's CSS is far more powerful than its original version.

Modern CSS includes:

  • Flexbox for one-dimensional layouts
  • CSS Grid for complex page layouts
  • Variables (Custom Properties)
  • Animations and transitions
  • Dark mode support
  • Responsive design tools
  • Container queries
  • Advanced selectors

Many tasks that once required JavaScript can now be accomplished using CSS alone.


Complete CSS Master Reference (Selectors + Properties)

1. CSS Selectors

TypeSelectorExampleDescription

Universal

*

* { }

Selects all elements

Element

element

p { }

Selects all paragraph tags

Class

.class

.box { }

Selects class elements

ID

#id

#header { }

Selects a unique element

Group

,

h1, h2 { }

Select multiple elements

Attribute

[attr]

[type="text"]

Select by attribute


2. CSS Combinators

TypeSelectorExampleDescription

Descendant

A B

div p

All inside elements

Child

A > B

div > p

Direct child only

Adjacent

A + B

h1 + p

Next sibling

General Sibling

A ~ B

h1 ~ p

All siblings after


3. Text Properties

PropertyExampleDescription

color

color: red;

Text color

text-align

text-align: center;

Alignment

text-decoration

underline

Underline/line-through

text-transform

uppercase

Capitalization

line-height

1.5

Spacing between lines

letter-spacing

2px

Space between letters


4. Font Properties

PropertyExampleDescription

font-family

Arial

Font style

font-size

16px

Text size

font-weight

bold

Thickness

font-style

italic

Style type

font

shorthand

Combined property


5. Box Model

PropertyExampleDescription

width

100px

Element width

height

100px

Element height

margin

10px

Outer spacing

padding

10px

Inner spacing

box-sizing

border-box

Includes padding in size


6. Background Properties

PropertyExampleDescription

background-color

#fff

Background color

background-image

url()

Image background

background-size

cover

Image scaling

background-repeat

no-repeat

Repeat control


7. Display & Layout

PropertyExampleDescription

display

flex

Layout type

visibility

hidden

Hide element

overflow

hidden

Content overflow


8. Positioning

PropertyExampleDescription

position

absolute

Position type

top

10px

Top position

left

10px

Left position

z-index

10

Layer order


9. Flexbox

PropertyExampleDescription

display

flex

Enable flexbox

justify-content

center

Main axis alignment

align-items

center

Cross-axis alignment

gap

10px

Spacing


10. CSS Grid

PropertyExampleDescription

display

grid

Enable grid

grid-template-columns

1fr 1fr

Columns setup

gap

10px

Spacing


11. Animation

PropertyExampleDescription

animation

fade 2s

Apply animation

transition

0.3s

Smooth effect

transform

scale(1.1)

Transform element


12. Pseudo-Classes & Elements

TypeSelectorExampleDescription

Pseudo-Class

: hover

a: hover

Mouse hover

Pseudo-Class

: focus

input: focus

Focused input

Pseudo-Element

::before

p::before

Before content

Pseudo-Element

::after

p::after

After content



🙌 THANK YOU 🙌

No comments:

Post a Comment

Advanced React Concepts for Beginners: Conditional Rendering, Context API & Custom Hooks (2026 Guide)

Advanced React Concepts: A Practical Guide React has evolved significantly over the years, and mastering its advanced concepts is essential ...