Correct Syntax for Adding an External Style Sheet (HTML)

Correct Syntax for Adding an External Style Sheet (HTML)

Verified Sources
Sep 12, 2026

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 use href to load external stylesheets)2
  • (ii) <style src='main.css'></style> ❌ incorrect (src is not the way <style> loads external CSS)2
  • (iii) <link rel='stylesheet' type='text/css' src='main.css'> ❌ incorrect because it uses src instead of href for the stylesheet URL; href is required.2
  • (iv) <link rel='stylesheet' type='text/css' href='main.css'> ✅ correct; it uses rel="stylesheet" and href correctly.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

  1. 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

  2. MDN Web Docs — <link> element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describes rel="stylesheet" and using href to load stylesheets. 2 3 4

  3. 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

  4. MDN Web Docs — link rel and stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (including rel and href). 2 3

Choose the Correct HTML Syntax for an External CSS File

  1. 1
    Step 1

    Use <link> for external stylesheets; <style> is for inline CSS.

  2. 2
    Step 2

    Add rel="stylesheet" to tell the browser this link is a stylesheet.

  3. 3
    Step 3

    Use href="main.css" (not src) to point to the external CSS file.

  4. 4
    Step 4

    "You may include type="text/css"; modern HTML often omits it, but it’s valid."2

    Footnotes

    1. MDN Web Docs — <link> element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describes rel="stylesheet" and using href to load stylesheets.

    2. MDN Web Docs — link rel and stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (including rel and href).

Why (iv) is correct

The <link> element for stylesheets uses:

  • rel="stylesheet" to declare the relationship
  • href="..." 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

OptionElementKey attributesCorrect for external CSS?
(i)stylehref
(ii)stylesrc
(iii)linkuses src instead of href
(iv)linkrel="stylesheet" + href

Footnotes

  1. MDN Web Docs — <link> element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describes rel="stylesheet" and using href to load stylesheets.

  2. MDN Web Docs — link rel and stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (including rel and href).

  3. 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.

  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.

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

  1. MDN Web Docs — <link> element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describes rel="stylesheet" and using href to 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

  1. MDN Web Docs — <link> element (stylesheet linking via rel/href) https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link - Describes rel="stylesheet" and using href to load stylesheets.

  2. MDN Web Docs — link rel and stylesheet examples https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attributes - Covers common attributes used when linking stylesheets (including rel and href).

How the Browser Uses the Markup to Load CSS

Find link stylesheet tags

Parse HTML

Browser scans for <link rel="stylesheet" ...> tags."

Request external CSS

Fetch CSS

Browser uses the href URL to download the CSS file."

Style the document

Apply styles

Fetched CSS rules are applied to elements in the page."

Quick FAQ

Knowledge Check

Question 1 of 3
Q1Single choice

Which syntax correctly adds an external stylesheet in HTML?