CSS: CSS Introduction Methods

🗓 Last updated: 2026-11-30👤 Written by: Casey✓ Reviewed by: MOTO🏷 Category: CSS Tutorial

CSS styles can be introduced into HTML documents in three ways: inline styles, internal styles, and external styles. Each method has its appropriate use cases.

✅ Best practice: For production environments, external stylesheets (<link>) are recommended. They completely separate HTML and CSS, allow browsers to cache CSS files, and improve loading speed when shared across multiple pages.

Properties in this section: color

1. Inline Styles

Inline styles write CSS directly in the HTML tag's style attribute.

▶ Example

▶ Try it Yourself

Characteristics:

Use cases: Rarely used. May be used in scenarios requiring dynamic style changes via JavaScript.


2. Internal Styles

Internal styles write CSS inside the HTML document's <head> tag, wrapped in a <style> tag.

▶ Example

▶ Try it Yourself

Characteristics:


3. External Styles (External Stylesheets)

External styles write CSS in a separate .css file, then use <link> tags to include it in HTML. This is the most commonly used method in actual development.

HTML file:

HTML
<!-- Document type declaration -->
<!DOCTYPE html>
<!-- HTML root element -->
<html lang="en">
<!-- Document head -->
<head>
<!-- Meta information -->
  <meta charset="UTF-8">
<!-- Page title -->
  <title>External Style example</title>
<!-- External resource link -->
  <link rel="stylesheet" href="style.css">
</head>
<!-- Document body -->
<body>
<!-- Paragraph -->
  <p>This text's style comes from an external CSS file</p>
</body>
</html>

style.css file:

CSS
p {
/* Text color */
  /* Text color */
  /* Text color */
  /* Text color */
  color: red;
/* Font style */
  /* Font style */
  /* Font style */
  /* Font style */
  font-size: 16px;
/* Font style */
  /* Font style */
  /* Font style */
  /* Font style */
  line-height: 1.8;
}

Characteristics:

(1) @import Method (Just for awareness)

⚠️ Note: @import loads referenced files after the CSS file finishes loading, causing "flash of unstyled content" on the page. This method is largely obsolete in modern projects, replaced by <link>.

Besides the <link> tag, you can also use @import in CSS files to import other CSS files:

▶ Example

▶ Try it Yourself

But this method has worse performance than <link> tags and is not recommended.


4. Comparison of Three Methods

Feature Inline Styles Internal Styles External Styles
Reusability Not reusable Single-page reuse Multi-page sharing
Structure/Style Separation ❌ Completely mixed ✅ Separated (same file) ✅ Completely separated
Priority Highest Medium Lowest
Loading Performance No extra requests No extra requests Requires extra HTTP request
Recommended Level ⭐ ⭐⭐ ⭐⭐⭐⭐⭐

5. Priority Rules

When all three methods appear simultaneously, the priority rule is:

Inline Styles > Internal Styles > External Styles

Note: This refers to the priority of inclusion methods, not selector specificity. Selector specificity is compared "within the same inclusion method," while inclusion method priority is only considered when styles from different methods conflict.


Properties in this section: color

❓ FAQ

Q How do I add CSS to an HTML file?
A The standard way is an external stylesheet: add <link rel="stylesheet" href="style.css"> inside <head> and keep your styles in a separate .css file. You can also embed styles with <style>...</style> in the head, or write inline styles with style="..." on the tag. For any new project, go external — no reason not to.
Q How do I link an external CSS stylesheet?
A <link rel="stylesheet" href="css/style.css">. Three gotchas: don't drop rel="stylesheet" (without it the browser ignores the file); get the relative path right — ./ means the same folder, ../ means one level up; and the link belongs inside <head>. Match the filename's capitalization exactly — Windows forgives it, the server returns 404.
Q My external stylesheet isn't showing up / not applying — why?
A Check in order: a wrong href path — look for a 404 on the css file in the Network panel; filename capitalization mismatch; selectors written wrong inside the CSS file so it loads but matches nothing; the browser serving a cached old copy — force refresh with Ctrl+F5; or encoding/BOM issues at the top of the file. The 404 in the Network panel is the most common culprit.
Q What's the difference between the three ways of adding CSS?
A Scope differs: inline styles affect one tag, embedded styles affect the current page, external styles are shared across pages. Loading differs too: link loads in parallel with HTML, while @import waits for the current CSS file to finish. Only the external file lets you change one place and restyle the whole site. Default to external, use embedded for one-off pages, and keep inline to a minimum.
Q What scenarios are the three CSS inclusion methods suitable for?
A External stylesheets are the standard for production (multiple pages share one .css file, browser caching is fast); internal styles are suitable for single-page applications or homepage above-the-fold styles; inline styles are only recommended for temporary debugging, not for extensive use in formal projects.
Q What's the difference between link and @import?
A link is an HTML tag, @import is CSS syntax. link loads simultaneously with HTML, @import waits for the CSS file to finish loading before loading referenced files, making it slower. link is the recommended approach.
Q Can I import one CSS file into another CSS file?
A Yes — @import url("reset.css"); at the very top of another CSS file. But it's not recommended: @import loads serially (the browser only discovers the next file after the current one finishes), which is slower than several <link> tags loading in parallel. Modern build tools (Vite, webpack) bundle instead; in a plain project, just use multiple link tags.
Q How do I quickly link a CSS file in VS Code?
A Emmet is built in: type link:css inside head and press Tab — it generates <link rel="stylesheet" href="css/style.css"> automatically. If the file doesn't exist yet, create css/style.css in the explorer first. Add the Live Server extension and the page reloads on save, so you never refresh manually.
Q Do inline styles have the highest priority?
A Inline styles do have very high priority, but !important can override them. It's recommended to use selector specificity for style management rather than relying on !important, otherwise maintenance becomes painful later.

📖 Summary

📝 Exercises

  1. Create an HTML file using inline, internal, and external methods to set different styles.
  2. Create an external style.css file defining paragraph colors and heading styles, then include it in HTML.
  3. On the same element, use all three methods to set the same property (like color), observe which one takes effect, and verify the priority rules.
  4. Modify colors in the style.css file, refresh the browser to see changes, and experience the maintenance convenience of external styles.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏