Inline styles are applied directly to HTML elements using the style attribute. They override all other types of styles and are useful for quick, one-off changes.
<p style="color: red;">This is red text.</p>Internal CSS is defined in a <style> tag inside the <head> section. It’s useful for styling a single HTML page.
<head>
<style>
body {
background-color: lightblue;
}
h1 {
color: navy;
}
</style>
</head>External CSS is written in a separate .css file and linked in the HTML document using a <link> tag. This is the preferred method for styling larger or multi-page websites.
<head>
<link rel="stylesheet" href="styles.css">
</head>The styles.css file should only contain CSS code and no HTML.
External stylesheets must end with a .css extension. This file should only include valid CSS rules:
/* styles.css */
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
}When styles conflict, CSS follows this order of priority:
Specificity, order in the document, and !important can also affect the final applied style.
Create a single HTML page that uses:
h1 element to blue<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Example</title>
<!-- Internal CSS -->
<style>
h1 {
color: blue;
}
</style>
<!-- External CSS -->
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>This is a Blue Heading</h1>
<!-- Inline CSS -->
<p style="color: red;">This paragraph is red using inline CSS.</p>
<p>This is a normal paragraph to see the background color effect.</p>
</body>
</html>
/* External CSS */
body {
background-color: lightgray;
}
Ask the AI if you need help understanding or want to dive deeper in any topic