Inline CSS is written directly on an element via the style attribute, internal CSS lives in a <style> tag in the <head>, and external CSS is loaded from a separate .css file via <link>. External styles are reusable and best for maintainability.
What is the difference between inline, internal, and external CSS?
Use guided tracks for structured prep, then practice company-specific question sets when you want targeted interview coverage.
Overview
CSS can be written directly inside HTML (inline), embedded within a <style> block (internal), or stored in a separate file (external). Understanding their differences is key to managing scalability, performance, and consistency in design.
Type | Defined In | Scope | Use Case |
|---|---|---|---|
Inline CSS | Inside an element’s | Affects one element only | Quick one-off styling or testing |
Internal CSS | Inside a <style> block in the <head> | Applies to one page only | Useful for small or unique pages |
External CSS | In a separate .css file linked with <link> | Applies to multiple pages | Best for maintainable, large projects |
Example: Inline CSS
<p style="color: red; font-size: 18px;">This is inline styling.</p>
Inline CSS applies directly to one element. It overrides both internal and external styles but is harder to maintain.
Example: Internal CSS
<style>
p {
color: blue;
font-size: 16px;
}
</style>
<p>This paragraph is styled internally.</p>
Internal CSS is written within the <head> section and applies only to that single HTML document.
Example: External CSS
<link rel="stylesheet" href="styles.css">
<p>This paragraph follows the external CSS rules.</p>
External CSS links to an outside file, ensuring consistent styles across multiple pages.
Performance and Maintenance
- External CSS loads once and can be cached, improving performance.
- Internal and inline CSS increase HTML file size and reduce maintainability.
- Inline styles override others due to higher specificity.
- External CSS is preferred for scalability and teamwork.
Think of it like this:
- Inline = Sticky note on one element.
- Internal = Rules written on one page.
- External = One master stylebook for the whole site.
- Inline: Fast but messy; use sparingly.
- Internal: Good for small, single-page projects.
- External: Best for consistency, performance, and maintainability.
- Always prefer external CSS in professional environments.