Course contentsShow
← Web Development
Lesson 597 of 2,98210. Typography and Design SystemsFree lesson

OOCSS (Object-Oriented CSS) Principles

Separating structure from skin and container from content for more flexible, reusable styles.

OOCSS (Object-Oriented CSS) Principles

You'll learn how to write more flexible, reusable CSS by separating structure from appearance and keeping containers independent from content.

What Is OOCSS?

Object-Oriented CSS (OOCSS) is a methodology that applies object-oriented programming concepts to CSS. Think of it like building with LEGO bricks: each piece serves a specific purpose and can be combined in countless ways. Rather than writing styles tied to specific page contexts, you create reusable "objects" that work anywhere.

The Two Core Principles

1. Separate Structure from Skin

Structure refers to layout properties (width, height, padding, margins), while skin refers to visual appearance (colors, borders, shadows, fonts).

Instead of creating monolithic styles that mix both:

/* Avoid: structure and skin mixed */
.product-card {
  width: 300px;
  padding: 20px;
  background: blue;
  border: 2px solid navy;
}

Separate them into reusable classes:

/* Structure */
.card {
  width: 300px;
  padding: 20px;
}

/* Skin */
.card-primary {
  background: blue;
  border: 2px solid navy;
}

Now you can use .card with different "skins" like .card-secondary or .card-alert.

2. Separate Container from Content

Don't style content based on where it lives. An <h2> should look the same whether it's in a sidebar or main content area:

/* Avoid: content depends on container */
.sidebar h2 {
  font-size: 18px;
}

/* Better: portable content style */
.subheading {
  font-size: 18px;
}

Key Takeaway: OOCSS creates flexible, reusable styles by keeping structure separate from appearance and making content styles independent of their containers—like modular building blocks you can use anywhere.