Inline CSS is used to apply a unique style directly to a single HTML
element using the style attribute.
Inline CSS works by directly injecting styles into HTML elements through the style attribute. It has the highest specificity in the CSS cascade, meaning it will override any other CSS rules targeting the same element. The specificity value for inline styles is 1000, compared to 100 for IDs and 10 for classes.
Important: Inline styles are parsed and applied immediately during HTML rendering, which can impact initial page load performance if overused.
<p style="color: blue; font-size: 16px;">This is an inline styled paragraph.</p>
Common Inline CSS Properties:
Internal CSS is defined within a <style> tag in the
<head> section of an HTML document.
Internal CSS follows the standard CSS cascade rules and specificity calculations. It allows for the use of all CSS selectors, pseudo-classes, and media queries. The styles are parsed when the HTML document loads and remain in the browser's memory for that page only.
Internal CSS supports advanced CSS features like:
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: green;
font-size: 18px;
}
</style>
</head>
<body>
<p>This paragraph is styled using internal CSS.</p>
</body>
</html>
External CSS is defined in a separate .css file and linked to
the HTML document using the <link> tag.
External CSS represents the most scalable approach to styling web applications. It implements the separation of concerns principle by completely separating structure (HTML) from presentation (CSS).
Key concepts:
<head>
<link rel="stylesheet" href="styles.css">
</head>
p {
color: red;
font-size: 20px;
}
| Feature | Inline CSS | Internal CSS | External CSS |
|---|---|---|---|
| Location | Inside HTML element | Inside <style> tag in <head> | Separate .css file |
| Reusability | ❌ No | ❌ No | ✅ Yes |
| Maintainability | ❌ Poor | ⚠️ Medium | ✅ Good |
| Overrides | ✅ Highest | ⚠️ Medium | ❌ Lowest |
| Use Case | Quick fixes, JS apps | Single-page apps | Large websites |