OnlineCBT Logo OnlineCBT
CSS Tutorial
CSS · LESSON 3

Inline, Internal, and External CSS

By Ratan Updated: 15 Oct 2026

Learn the 3 ways to add CSS to web pages and when to use each approach.

Level: Beginner to Advanced
Duration: ~60 Mins Deep-Dive

Choose where a stylesheet lives

CSS can be written in an element's style attribute, a style element, or a separate linked file. These locations affect reuse and maintenance. They do not change the basic syntax of properties and values.

Three forms


One paragraph

In styles.css, write ordinary rules without a style wrapper:

.summary {
  color: #1d4ed8;
  line-height: 1.6;
}

When each is useful

Inline styles can express a small dynamic value, but repeating them on many elements makes consistent editing difficult. Internal styles suit isolated demonstrations. External stylesheets support multiple pages and may be cached independently. For a growing project, keep shared component styles in a predictable file structure.

Debug a missing stylesheet

  1. Check the href relative to the HTML document's URL, not your mental picture of the project folder.
  2. Open the Network panel and confirm that the CSS request returns a stylesheet, not a 404 HTML page.
  3. Check the response content type and any browser console errors.
  4. Inspect whether the rule is loaded but overridden by another declaration.

A relative image URL inside a stylesheet resolves relative to that stylesheet's URL. This differs from an inline style's base URL and can explain why moving CSS breaks background images.

Cascade note

Inline author declarations normally outrank ordinary author stylesheet rules for the same property, but “inline always wins” is an oversimplification: importance, origin, layers and other cascade rules also matter. Avoid solving ordinary maintenance problems by scattering !important.

Practice

Move a card's internal stylesheet into styles.css and link it from two pages. Confirm that changing the shared file updates both. Intentionally break the filename once, observe the failed request, then repair the path.

📝 Live Lesson Practice

HTML/CSS JavaScript Python C++ C PHP
⌨️ Practice Inputs (लाइव इनपुट भरें) (खाली होने पर RED, भरने पर GREEN underline)
💻 Code Editor (Monaco VS Code Engine)
👀 Live Preview
पता संपर्क करें

+91 7877547686

ई-मेल

onlinecbtportal@gmail.com

हेल्पलाइन नंबर

+91 7877547686


डाउनलोड करने के लिए क्लिक करें
Get it on Google Play

ऐप डाउनलोड करने
के लिए Google Play पर
उपलब्ध है

WhatsApp Chat