HTML · Chapter 13 of 45

HTML and CSS Basics

CSS (Cascading Style Sheets) controls the visual presentation of HTML elements — colors, fonts, layout, and spacing. HTML and CSS work together but serve different purposes: structure versus style.

There are three ways to add CSS: inline (style attribute), internal (<style> tag in head), and external (a separate .css file linked via <link>). External CSS is the recommended approach for real projects.

Syntax
<link rel="stylesheet" href="styles.css">

Linking external CSS

Use <link rel="stylesheet" href="styles.css"> inside <head> to apply styles from a separate file, keeping HTML clean and styles reusable across pages.

Internal CSS

A <style> block inside <head> lets you write CSS rules that apply to the whole current page without an external file.

Example 1 (html)
<head>
  <link rel="stylesheet" href="styles.css">
</head>
Output
(applies styles.css to the page)

The link tag connects an external stylesheet to the HTML document.

Example 2 (html)
<head>
<style>
  p { color: green; }
</style>
</head>
<body>
<p>Green text</p>
</body>
Output
Green text

Internal CSS in a <style> block affects all matching elements on the page.

Key points

  • CSS controls layout, color, fonts, and spacing.
  • Three ways to add CSS: inline, internal, external.
  • External stylesheets are linked with <link> in <head>.
  • External CSS is best practice for maintainability.
💡 Note: CSS specificity and order determine which rule wins when styles conflict.

📝 Quick Quiz

1. What does CSS stand for?

2. Which tag links an external stylesheet?

3. Where does internal CSS usually go?