CSS styles make web pages look nice and organized. You can add CSS in three ways to control how your page looks.
Inline, internal, and external CSS
/* Inline CSS */ <tag style="property: value;">Content</tag> /* Internal CSS */ <style> selector { property: value; } </style> /* External CSS */ <link rel="stylesheet" href="styles.css">
Inline CSS goes inside an HTML tag using the style attribute.
Internal CSS is placed inside a <style> tag in the HTML <head>.
External CSS is in a separate file linked to the HTML.
<p style="color: blue;">This text is blue.</p><style>
h1 {
color: green;
}
</style>
<h1>Green heading</h1><link rel="stylesheet" href="styles.css"> /* In styles.css file */ h2 { font-size: 2rem; color: red; }
This page uses all three CSS types: internal CSS styles the body and h1, inline CSS colors one paragraph purple, and external CSS (in styles.css) styles the h2 heading.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Types Example</title> <style> /* Internal CSS */ body { font-family: Arial, sans-serif; background-color: #f0f0f0; } h1 { color: darkblue; } </style> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Internal CSS Heading</h1> <p style="color: purple;">This paragraph uses inline CSS to be purple.</p> <h2>External CSS Heading</h2> </body> </html>
Inline CSS is quick but not good for many elements because it mixes style with content.
Internal CSS is good for single pages but can get messy if styles grow large.
External CSS keeps styles in one place, making it easy to update many pages at once.
Inline CSS styles one element directly inside the tag.
Internal CSS goes inside a <style> tag in the HTML head for that page.
External CSS is in a separate file linked to HTML, best for reuse and organization.