ProgramGuru

Introduction to CSS

Introduction to CSS

CSS controls the appearance of HTML. The same heading and paragraph can be presented with different colors, spacing, typography and layout without changing their meaning.

What you’ll learn

  • Separate HTML structure from CSS presentation.
  • Explain what a selector and declaration change.
  • Style an announcement without altering its HTML meaning.

Understand the concept

HTML describes the content and structure of a page. CSS (Cascading Style Sheets) describes how that content should look. A browser first builds the page from HTML, then applies matching style rules to the elements.

A single stylesheet can style many pages. This is why a site can change its visual identity without rewriting every heading or paragraph.

Visualize the relationship

HTML structureCSS rulesRendered pageThe browser combines meaningful HTML with matching CSS rules.
The browser combines meaningful HTML with matching CSS rules.

Unstyled content

The markup already contains meaningful elements.

HTML

<article class="intro-card"><h3>Fresh Ideas</h3><p>Start with a clear message.</p></article>

CSS

/* No stylesheet rules yet. */

Rendered output

Fresh Ideas

Start with a clear message.

Observe: The heading and paragraph appear using the browser’s default styling.

Add a simple design

Apply typography, spacing and a surface to the same markup.

HTML

<article class="intro-card"><h3>Fresh Ideas</h3><p>Start with a clear message.</p></article>

CSS

.intro-card { background: #eff6ff; border-radius: 12px; padding: 20px; font-family: Arial, sans-serif; }
.intro-card h3 { margin: 0 0 8px; color: #1d4ed8; }
.intro-card p { margin: 0; color: #334155; }

Rendered output

Fresh Ideas

Start with a clear message.

Observe: Only CSS changed; the HTML elements and the words are identical.

Explain the result

A rule selects HTML elements, assigns properties, and influences their appearance. CSS never replaces the underlying text or HTML semantics.

Compare the two examples: identify the selector, each changed property, and which visible part of the output proves that the CSS took effect.

Common mistakes to avoid

  • CSS changes presentation, not the fundamental meaning of an HTML element.
  • A stylesheet does not automatically affect every element; selectors determine matches.

Try it yourself

Change the heading color to green and increase card padding to 28px. Compare the two versions without changing the HTML.

Before changing the code, predict what will change. Then verify by checking the rendered result.

Check your understanding

What is the main responsibility of CSS?
Choose one answer. You can try again.

Answer and explanation

To control visual presentation

CSS styles the presentation of HTML elements; HTML supplies the structure and content.

What you should remember

Keep HTML meaningful and use CSS to express the visual design.

Revisit the rendered examples if the rule still feels abstract. Change one declaration at a time so you can connect cause and effect.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: How CSS Works →