HTML chapters

Chapter 14 of 17

Linking styles and scripts

Try this in our HTML Compiler →

The idea

HTML loads other resources through links and scripts, not through an import statement in markup. Keep a stylesheet link in head. A deferred classic script runs after parsing, and a module script has its own module rules. Resource paths must refer to files that actually exist in the project.

Worked example

<!-- In head, when these files exist: -->
<link rel="stylesheet" href="styles.css">
<script src="app.js" defer></script>

What to check

These lines reference files; they do not create them. A network error or incorrect path can leave a valid HTML page unstyled.

Practice task

Create styles.css beside a local index.html and style its heading. Inspect whether the stylesheet loads successfully.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on