Content · Web Development · HTML

Connecting HTML to External CSS

Connecting HTML to External CSS: The result depends on browser support and, in examples with script elements, on JavaScript being allowed. Includes a practical HTML example and an explanation.

2 views Published Oct 19, 2026 Updated Oct 19, 2026 Admin

A useful interface does not need to be complicated. Start with native HTML, then add JavaScript only when you need it.

What You Need to Know


An external stylesheet is linked from the document head using link rel=stylesheet. The HTML holds the content while the CSS file holds the shared visual rules.

In this example: style the headings of an article.

Try the Example


Take a look at the example. We’ll explain the important lines right below it.

<link rel="stylesheet" href="styles/site.css">
<main class="page-layout">
    <h1>Our club</h1>
    <p>HTML describes the content; CSS controls its appearance.</p>
</main>

Let’s Read the Code


  • <link>: Link connects the document to metadata relationships or resources; it is not a visible anchor.
  • <main>: The main element marks the primary page content.
  • rel: Rel defines a relationship, such as a canonical page URL or stylesheet.
  • href: Href is the URL to a related resource or destination.

Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.

What Happens in the Browser?


When this example includes JavaScript, it supplies behavior that ordinary HTML does not automatically provide. Always think about a fallback.

Start with native behavior. Details, dialog, and popover each solve a different interface problem. Choose the simplest control that actually matches what a visitor wants to do, then test focus and dismissal as well as appearance.

Your Turn


Run this on a local development server if it loads modules or resources. Change the visible text or trigger and check what still works with scripts disabled.

Common Beginner Mistakes


  • Assuming new HTML syntax works in every browser without testing.
  • HTML supplies structure; JavaScript is necessary for the scripted behavior in this example. Check keyboard access and focus movement too.

Key Takeaways


  • An external stylesheet is linked from the document head using link rel=stylesheet.
  • <link>: Link connects the document to metadata relationships or resources; it is not a visible anchor.
  • Test the behavior you expect rather than trusting how the snippet looks in your editor.
Share this resourceSend this page to someone who may find it useful.