Ways to Add CSS
- External CSS — link a
.cssfile (recommended) - Internal CSS — write CSS in a
<style>block - Inline CSS — use the
styleattribute on elements
CSS (Cascading Style Sheets) is the language that styles HTML pages. It controls layout, colors, fonts, spacing, and responsiveness.
.css file (recommended)<style> blockstyle attribute on elements
<!-- index.html -->
<head>
<link rel="stylesheet" href="styles.css">
</head>
/* styles.css */
body {
font-family: Arial, sans-serif;
line-height: 1.5;
}
External files keep code organized and cacheable across pages.
<style>
h1 { color: #1E88E5; }
p { color: #333; }
</style>
Useful for page-specific styles. Avoid overusing to keep CSS reusable.
<p style="color: red; font-weight: bold;">
Inline CSS example
</p>
Good for quick tests; avoid in production—harder to maintain, lower reusability.
<!-- HTML -->
<h1>Welcome to CSS</h1>
<p class="lead">Styled by external CSS</p>
/* CSS */
h1 {
color: #1E88E5;
text-align: center;
}
.lead {
font-size: 18px;
color: #555;
}
Tips:
rem, px) and naming conventions.