You can attach CSS to an HTML page using three methods: linking an external .css file, writing an internal style block inside head, or adding an inline style attribute on an element. Picking the right method affects page speed, caching, and long-term maintainability.
styles.css file and loaded via a link tag with rel="stylesheet" inside head. This is best for production sites because browsers cache the file once across every page visit.style block in the document head. Useful for isolated single-page prototypes or injecting small critical-path CSS.style="..." attribute. Highest cascade priority, ideal only for dynamic JavaScript measurements or HTML email clients that strip head styles.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS Insertion Methods</title>
<link rel="stylesheet" href="/css/base.css">
<style>
.status-pill {
display: inline-block;
padding: 4px 10px;
background-color: #dcfce7;
color: #166534;
border-radius: 999px;
font-weight: 600;
}
</style>
</head>
<body>
<span class="status-pill">Build Passing</span>
<p style="color: #475569;">Inline styles override external and internal rules on this element.</p>
</body>
</html>
When rules conflict, inline style attributes override both internal and external rules. Between internal style blocks and external link tags, whichever appears last in head wins when specificity matches.
style tags inside a .css file: External .css files must contain pure CSS only—HTML tags inside .css break the parser.link tags at the bottom of body: Deferring core stylesheets causes visible layout flashes before styles paint.External stylesheets are fastest across repeat views because the browser downloads styles.css once and reuses it from cache on every page.
Yes. Using @import inside one CSS file forces sequential network downloads instead of parallel loading, so prefer link tags in HTML or build-time bundling.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.