Home 〉 CSS Tutorials 〉 CSS Inline, Internal & External Styling | Add CSS to HTML Easily
CSS Inline, Internal & External Styling | Add CSS to HTML Easily !
Wondering how to apply CSS to your HTML documents?
This tutorial explores the three primary methods of adding CSS: inline, internal, and external. Understand the pros and cons of each approach and learn best practices for organizing your styles effectively.
To style your HTML elements with CSS, you need to add CSS using one of three methods:
Each method has its own use case. In this post, we'll explain each one in simple terms with working examples so you can easily decide which method suits your needs.
Inline CSS is applied directly to an HTML element using the 'style' attribute.
html syntax ✍
<tag style="property: value;"></tag>
<tag style="property: value;"></tag>
Example 📄
<p style="color: red; font-size: 18px;">This is red text with inline CSS.</p>
Internal CSS is written inside a '<style>' tag in the '<head>' section of your HTML document.
Example 📄
<head>
<style>
selector {
property: value;
}
</style>
</head>
Example 📄
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: blue;
text-align: center;
}
</style>
</head>
<body>
<h1>Welcome to My Website</h1>
</body>
</html>
External CSS is stored in a separate '.css' file and linked to your HTML document using the '<link>' tag.
Example 📄
<link rel="stylesheet" href="styles.css">
Example 📄
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p class="intro">This is a paragraph styled with external CSS.</p>
</body>
</html>
Example 📄
.intro {
color: green;
font-size: 20px;
}
Method | Where Used | Reusable | Best Use Case |
---|---|---|---|
Inline | Inside element | ❌ | Quick fixes or testing |
Internal | Inside `<head>` | ❌ | Single-page apps |
External | Separate .css file | ✅ | Multi-page websites, real projects |
Choosing the right CSS styling method depends on your project:
Stick to 'external CSS' as a best practice in real-world development!
'Inline' is written inside an element, 'internal' is inside a '<style>' tag in the HTML head, and 'external' is in a separate '.css' file.
'External CSS' is best because it keeps code clean and styles reusable.
Yes, but it's not recommended. Use one method consistently to avoid confusion and conflicts.