Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Using CSS with HTML – `<link>` and `<st | HTML Course lesson | BraveProgrammer
  1. Courses
  2. /
  3. HTML Course

Lesson 16 of 55

·HTML

Using CSS with HTML – `<link>` and `<style>`

8 min

Course progress29%

What you'll learn

Keep these ideas in mind as you work through the lesson.

5 points
  • Linking external CSS with `<link rel='stylesheet'>`
  • Embedding internal CSS with `<style>` and when to use it
  • Specificity hierarchy between external, internal, and inline styles
  • Conditional loading with `media` attribute
  • Best practices for stylesheet organization and caching

Connecting Stylesheets

Two main ways to apply CSS:

  • External – <link rel='stylesheet' href='styles.css'> placed inside <head>.
  • Internal – <style> block within <head> for page‑specific rules.
<head>
  <link rel='stylesheet' href='styles.css' />
  <style>
    .highlight { background: yellow; }
  </style>
</head>

Loading order

  1. External stylesheet – fetched first, can be cached.
  2. Internal <style> – parsed after external CSS, can override it.
  3. Inline style= – highest specificity, used sparingly.

Media queries in <link>

You can conditionally load a stylesheet based on media features:

<link rel='stylesheet' href='print.css' media='print' />

The browser loads print.css only when printing or previewing.


Quick checklist for CSS inclusion

  1. External stylesheet linked with rel='stylesheet'? ✅
  2. media attribute used where appropriate? ✅
  3. Internal <style> only for critical CSS? ✅
  4. No inline style= unless absolutely necessary? ✅

If any answer is “no”, refactor your code.

Make it stickPractice what you've learned1 quiz · 2 practical tests · Optional activities from HTML CourseBrowse activities
Previous lessonSVG BasicsContinue to lesson 17Inline vs External CSSBack to HTML Course curriculum