Chapter 15: HTML & CSS Styling Core

Core of HTML & CSS Styling — the absolute must-master foundation that controls how every pixel looks on the screen.

This is the layer where you go from “plain boring text” to “wow, this looks like a real modern website”. Everything else (Flexbox, Grid, animations, Tailwind, dark mode…) builds on top of these core concepts.

I’ll explain it like we’re sitting together in VS Code, line-by-line, with real examples you can copy-paste right now.

1. What Actually is “Styling Core” in CSS?

The core includes:

  • How CSS selects elements to style (Selectors)
  • How styles cascade and override each other (Cascade & Specificity)
  • How styles inherit from parent to child (Inheritance)
  • The Box Model — every visible thing is a box
  • Basic properties you use every single day (color, typography, spacing, borders, backgrounds)

Master these → you can style almost anything. Ignore them → you fight CSS forever.

2. Core Concept #1 – Selectors (How CSS Finds What to Style)

Selector Type Example What it targets Specificity (higher = stronger)
Element p { color: navy; } All <p> tags 0,0,0,1
Class .card { padding: 20px; } Any element with class=”card” 0,0,1,0
ID #header { background: #1e40af; } Element with id=”header” (unique!) 0,1,0,0
Attribute [type=”email”] { border: 2px solid; } Any input with type=”email” 0,0,1,0
Pseudo-class a:hover { color: red; } Link when mouse is over 0,0,1,0
Pseudo-element p::first-letter { font-size: 3rem; } First letter of every paragraph 0,0,0,1
Combinator .card > h3 Direct child h3 inside .card Adds parent specificity

Quick rule of thumb 2026:

  • Use classes for almost everything (reusable & maintainable)
  • Use IDs only for JavaScript targets or one-time anchors
  • Avoid overusing element selectors (too broad)

3. Core Concept #2 – The Cascade & Specificity

CSS = Cascading Style Sheets → styles fight each other, winner is decided by rules.

Order of importance (highest to lowest):

  1. Inline styles (style=”color:red;”) → almost never use (bad for maintenance)
  2. !important → very last resort (avoid like plague)
  3. Specificity (calculated as a,b,c,d)
    • a = inline style (1,0,0,0)
    • b = ID selectors (#id)
    • c = classes, attributes, pseudo-classes
    • d = elements, pseudo-elements
  4. Source order — last declaration wins if specificity is equal

Example specificity battle:

CSS

4. Core Concept #3 – Inheritance

Some properties pass down from parent to children automatically:

Inherited by default:

  • color
  • font-family, font-size, font-weight
  • line-height
  • text-align
  • visibility, cursor

Not inherited (must set on each element):

  • margin, padding, border
  • background, width, height
  • display, position

Quick tip: Set global typography on body or :root:

CSS

5. Core Concept #4 – The Box Model (Most Important!)

Every visible element = rectangular box with 4 layers:

Content → text/image (width & height) Padding → inside space Border → line around padding Margin → outside space

Modern fix (put this at the very top of every CSS file):

CSS

Without border-box: width: 300px + padding 20px + border 10px = total 350px (annoying math) With border-box: total width stays 300px (padding & border eat inside)

6. Your “Styling Core” Demo Page – Build This Now!

index.html

HTML

style.css (all core concepts in one file)

CSS

Save both → right-click index.html → Open with Live Server.

Play with it:

  • Change body { color: #111827; } → see inheritance everywhere
  • Add style=”background: pink;” to one .card → see inline win
  • Modify .card.featured background → only featured cards change

Quick Core Checklist (Bookmark This!)

  • * { box-sizing: border-box; } at top
  • Use classes > IDs > elements
  • Set global typography on body or :root
  • Understand why .card.featured beats .card
  • Know when inheritance helps (fonts/colors) and when it doesn’t (margins)
  • Avoid !important unless debugging

How does the page look/feel? Try changing one color and see the cascade in action?

Next steps you might want (just tell me):

  • “teach me Flexbox as next core”
  • “CSS variables for theming”
  • “specificity battles practice”
  • “positioning core (static/relative/absolute)”
  • “modern reset with better typography”

You’re nailing the real heart of CSS now — keep going champ! 🚀 Chai break ho gaya? 😄

You may also like...

Leave a Reply

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