HTML defines document structure while CSS controls visual design, spacing, colors, and responsive layout. You can attach CSS rules to an HTML document in three ways: inline attributes, internal style blocks, or external .css files.
styles.css file and link it inside head with link rel="stylesheet". This is the standard approach for multi-page sites because browsers cache the CSS file once across every page.style block inside the head section to style a single standalone page.style="..." attribute directly onto one HTML element for isolated overrides or email templates.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML and CSS Example</title>
<!-- External stylesheet link -->
<link rel="stylesheet" href="/css/styles.css">
<!-- Internal CSS block -->
<style>
.notice-card {
background-color: #f1f5f9;
border-left: 4px solid #2563eb;
padding: 16px;
font-family: system-ui, sans-serif;
}
</style>
</head>
<body>
<div class="notice-card">
<h2>Styled with Internal CSS</h2>
<p style="color: #334155;">This paragraph also applies an inline text color override.</p>
</div>
</body>
</html>
When conflicting rules target the same element, inline styles win over internal and external styles. Between internal style blocks and external link stylesheets, whichever appears lower in the head section wins if specificity matches.
link rel="stylesheet" inside body: Putting stylesheets in body causes a flash of unstyled content before styles load. Keep stylesheet links in head.style tags inside an external .css file: Write pure CSS rules in .css files with zero HTML tags.css/main.css vs /css/main.css) when moving pages into subfolders.External .css files are best because they keep HTML clean, prevent repeated rules, and allow browsers to cache styles between page visits.
Yes. You can add multiple link tags in head, and later stylesheets override earlier ones when selector specificity is equal.
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.
You've completed this section! Take a quick 5-question quiz to check your understanding.