Skip to content

03. Internal CSS

Internal CSS (also called embedded CSS) is placed within a <style> element in the HTML document’s <head> section. It allows you to define styles for the entire page without creating a separate CSS file. Internal CSS is useful for single-page styles or page-specific styling.

<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
h1 {
color: #333;
}
</style>
</head>
<body>
<h1>Title</h1>
<p>Content</p>
</body>
</html>

All code in one file:

<head>
<style>
/* All styles here */
</style>
</head>

Styles apply only to current page:

<style>
/* Page-specific styles */
</style>

Can’t share across pages:

<!-- Each page needs its own style tag -->

Increases HTML file size:

<!-- Large style blocks make HTML files bigger -->
<!-- Good: Single-page application -->
<style>
/* Page-specific styles */
</style>
<!-- Good: External CSS for multiple pages -->
<link rel="stylesheet" href="styles.css">