CODY ← Back to Courses
CSS

CSS — Cascading Style Sheets

The design layer of the web. Control colors, fonts, layouts, animations and make any HTML page look stunning.

Visual Design Layouts & Animations Beginner Friendly

What is CSS?

CSS — Cascading Style Sheets — is the language used to style HTML elements. It controls colors, fonts, spacing, layouts and animations.

how css works
/* selector { property: value; } */

h1 {
  color: crimson;
  font-size: 48px;
  font-weight: bold;
}

p {
  color: #666;
  line-height: 1.6;
  max-width: 600px;
}

🎨 Styling

Colors, fonts, sizes, borders — every visual detail is controlled by CSS.

📐 Layout

Flexbox and Grid let you build any layout — from simple rows to complex dashboards.

✨ Animation

Transitions and keyframe animations bring your pages to life without JavaScript.

Selectors

Selectors are how CSS targets specific HTML elements. Choosing the right selector is the key to clean, maintainable styles.

selector types
/* Element selector — targets all <p> tags */
p { color: white; }

/* Class selector — targets elements with class="card" */
.card { background: #222; border-radius: 10px; }

/* ID selector — targets the element with id="header" */
#header { position: fixed; top: 0; }

/* Descendant — targets <a> inside .navbar */
.navbar a { text-decoration: none; }

/* Pseudo-class — styles element on hover */
button:hover { background: crimson; transform: scale(1.05); }

/* Pseudo-element — styles first line of text */
p::first-line { font-weight: bold; }
💡 Tip: Prefer classes over IDs for styling. IDs are harder to override due to higher specificity. Use IDs only for JavaScript or unique page landmarks.

The Box Model

Every HTML element is a rectangular box. The box model describes the layers around its content: padding, border, and margin.

LIVE DIAGRAM

margin
border
padding
CONTENT
box model
.card {
  width: 300px;          /* content width */
  padding: 20px;         /* space inside the border */
  border: 2px solid #264de4; /* visible outline */
  margin: 16px auto;    /* space outside, auto=center */
  box-sizing: border-box; /* padding included in width */
}

Colors & Typography

CSS supports multiple color formats and rich font control. Google Fonts gives you thousands of free typefaces.

colors & fonts
/* Color formats */
.example {
  color: crimson;              /* named */
  background: #264de4;        /* hex */
  border-color: rgb(38,77,228); /* rgb */
  box-shadow: 0 0 20px rgba(38,77,228, 0.4);
}

/* CSS Variables — define once, use everywhere */
:root {
  --primary: #264de4;
  --text: #e8e8f0;
}
h1 { color: var(--primary); }

/* Typography */
body {
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: 0.02em;
}

COLOR PALETTE EXAMPLE

#264de4
#2965f1
#e44d26
#f7df1e
#3c873a
#181818

Flexbox

Flexbox is a one-dimensional layout system. It arranges items in a row or column and gives you powerful alignment control.

flexbox example
.container {
  display: flex;
  justify-content: space-between; /* horizontal alignment */
  align-items: center;            /* vertical alignment */
  gap: 20px;                      /* space between items */
  flex-wrap: wrap;                /* wrap to next line */
}

.item {
  flex: 1;         /* grow equally */
}

FLEX DEMO — justify-content: space-between

Item 1
Item 2
Item 3

CSS Grid

CSS Grid is a two-dimensional layout system — perfect for building complex page layouts with rows AND columns at the same time.

grid example
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr); /* 3 equal columns */
  gap: 20px;
}

/* Make an item span 2 columns */
.featured {
  grid-column: span 2;
}

GRID DEMO — 3 columns

1
2 (spans 2)
3
4
5

Transitions & Animations

CSS animations bring pages to life. Transitions handle simple state changes; @keyframes handle complex sequences.

transitions
.btn {
  background: #264de4;
  transition: all 0.3s ease; /* smooth change on hover */
}
.btn:hover {
  background: #2965f1;
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(38,77,228, 0.4);
}
keyframe animation
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeIn 0.6s ease forwards;
}

Responsive Design

Media queries let you apply different styles based on screen size — making your site look great on phones, tablets and desktops.

media queries
/* Default — for all screens */
.grid { grid-template-columns: repeat(3, 1fr); }

/* Tablet — screens up to 768px */
@media (max-width: 768px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .navbar ul { display: none; } /* hide menu */
}

/* Mobile — screens up to 480px */
@media (max-width: 480px) {
  .grid { grid-template-columns: 1fr; }
  h1 { font-size: 28px; }
}
📱 Mobile First: Start your CSS for small screens and use min-width media queries to add styles for larger screens. This approach is called "Mobile First" and is the industry standard.

🎨 Project: Style the Profile Card

Take the HTML profile card from the previous lesson and make it look great with CSS. Here's a complete styled version:

styles.css
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #0f0f0f;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: Arial, sans-serif;
}

.card {
  background: #181818;
  border: 1px solid #264de4;
  border-radius: 16px;
  padding: 36px;
  text-align: center;
  width: 320px;
  box-shadow: 0 0 30px rgba(38,77,228, 0.2);
  animation: fadeIn 0.6s ease;
}