Correct Syntax for Adding an External Style Sheet (HTML)
To add an external CSS file in HTML, you use the <link> element with rel="stylesheet" and an href attribute pointing to the CSS file URL. This is the standard browser mechanism for stylesheet inclusion.2
A helpful contrast is:
Given the options:
- (i)
<style href='main.css'></style>❌ incorrect (the<style>element does not usehrefto load external stylesheets)2 - (ii)
<style src='main.css'></style>❌ incorrect (srcis not the way<style>loads external CSS)2 - (iii)
<link rel='stylesheet' type='text/css' src='main.css'>❌ incorrect because it usessrcinstead ofhreffor the stylesheet URL;hrefis required.2 - (iv)
<link rel='stylesheet' type='text/css' href='main.css'>✅ correct; it usesrel="stylesheet"andhrefcorrectly.2
Therefore, the correct syntax is (iv):
<link rel='stylesheet' type='text/css' href='main.css'>2
Key terms you’ll see in this topic:
- external stylesheet
- [stylesheet link element]{def="HTML tag used to connect an external stylesheet to a document"}
- href attribute
- rel attribute
Footnotes
-
MDN Web Docs —
<style>element (internal CSS) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style - Explains the purpose of<style>for embedding CSS rules. ↩ ↩2 ↩3 -
MDN Web Docs —
<link>element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describesrel="stylesheet"and usinghrefto load stylesheets. ↩ ↩2 ↩3 ↩4 -
WHATWG HTML Standard —
<style>element definition https://html.spec.whatwg.org/multipage/semantics.html#the-style-element - Specifies<style>content model for inline CSS. ↩ ↩2 -
MDN Web Docs —
linkreland stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (includingrelandhref). ↩ ↩2 ↩3
HTML CSS Link Tag Explained
Choose the Correct HTML Syntax for an External CSS File
- 1Step 1
Use
<link>for external stylesheets;<style>is for inline CSS. - 2Step 2
Add
rel="stylesheet"to tell the browser this link is a stylesheet. - 3Step 3
Use
href="main.css"(notsrc) to point to the external CSS file. - 4Step 4
"You may include
type="text/css"; modern HTML often omits it, but it’s valid."2Footnotes
-
MDN Web Docs —
<link>element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describesrel="stylesheet"and usinghrefto load stylesheets. ↩ -
MDN Web Docs —
linkreland stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (includingrelandhref). ↩
-
Why (iv) is correct
The <link> element for stylesheets uses:
rel="stylesheet"to declare the relationshiphref="..."to provide the resource URL
This matches the standard stylesheet linking pattern documented for HTML.2
In contrast, the <style> element is meant to contain CSS text inside the document, not to reference an external CSS file via href or src attributes.2
Quick syntax comparison
| Option | Element | Key attributes | Correct for external CSS? |
|---|---|---|---|
| (i) | style | href | ❌ |
| (ii) | style | src | ❌ |
| (iii) | link | uses src instead of href | ❌ |
| (iv) | link | rel="stylesheet" + href | ✅ |
Footnotes
-
MDN Web Docs —
<link>element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describesrel="stylesheet"and usinghrefto load stylesheets. ↩ -
MDN Web Docs —
linkreland stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (includingrelandhref). ↩ -
MDN Web Docs —
<style>element (internal CSS) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style - Explains the purpose of<style>for embedding CSS rules. ↩ -
WHATWG HTML Standard —
<style>element definition https://html.spec.whatwg.org/multipage/semantics.html#the-style-element - Specifies<style>content model for inline CSS. ↩
Pro Tip: Minimal valid stylesheet link
You can often write just: <link rel="stylesheet" href="main.css"> since type="text/css" is commonly omitted in modern HTML usage.
Footnotes
-
MDN Web Docs —
<link>element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describesrel="stylesheet"and usinghrefto load stylesheets. ↩
Common mistake: using src with <link>
The stylesheet URL for <link> must be placed in href, not src. Using src won’t load the stylesheet as intended.2
Footnotes
-
MDN Web Docs —
<link>element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describesrel="stylesheet"and usinghrefto load stylesheets. ↩ -
MDN Web Docs —
linkreland stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (includingrelandhref). ↩
How the Browser Uses the Markup to Load CSS
Find link stylesheet tags
Parse HTMLBrowser scans for <link rel="stylesheet" ...> tags."
Request external CSS
Fetch CSSBrowser uses the href URL to download the CSS file."
Style the document
Apply stylesFetched CSS rules are applied to elements in the page."
Quick FAQ
Knowledge Check
Which syntax correctly adds an external stylesheet in HTML?
Explore Related Topics
8085 Microprocessor Flags: Correct Answer and Conceptual Explanation
The 8085 microprocessor’s flag register contains five active status flags that are automatically set after arithmetic and logical operations.
- The 8‑bit flag register uses only five bits: Sign (S), Zero (Z), Auxiliary Carry (AC), Parity (P), and Carry (CY).
- These flags guide conditional branch instructions such as jump‑on‑zero or jump‑on‑carry.
- Although the register is 8 bits wide, the remaining three bits are unused/reserved, a common source of exam mistakes.
- The Auxiliary Carry flag is especially important for BCD arithmetic.
Which of the following is a complementary approach to function-oriented approach? (i) Object-oriented analysis (ii) Object-oriented design (iii) Structured approach (iv) Both object-oriented analysis and design
Choosing the Correct HTML Tag for Bold Text