CodingRider

Sign In

🟢 Inline, Internal, External CSS

CSS can be applied to HTML in three main ways: Inline, Internal, and External. Each method has its own use case and importance depending on the situation.

1.Inline CSS


Definition: Styles are applied directly to an individual HTML element using the style attribute.

🔧 Example:


<p style="color: red; font-size: 18px;">This is an inline styled paragraph.</p>

🖼️ Output Behavior:


The paragraph text will be red and sized at 18px.
🔎 Use Case:
Useful for quick changes or overriding other styles.
Not recommended for large-scale styling or maintainability.

2. Internal CSS

Definition: Styles are written within a <style> tag inside the <head> section of an HTML document.

🔧 Example:



<!DOCTYPE html>
<html>
<head>
  <style>
    h1 {
      color: blue;
    }
    p {
      font-size: 16px;
    }
  </style>
</head>
<body>
  <h1>This is a heading</h1>
  <p>This is a paragraph with internal styling.</p>
</body>
</html>

🖼️ Output Behavior:


The heading becomes blue.
The paragraph has a 16px font size.
🔎 Use Case:
Good for single-page websites or testing styles quickly.

3. External CSS
Definition: Styles are written in a separate .css file and linked using the tag in the HTML .

🔧 Example:


CSS file (styles.css):
body {
  background-color: #f0f0f0;
  font-family: Arial, sans-serif;
}
h2 {
  color: green;
}

HTML file:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <h2>This is a styled heading</h2>
</body>
</html>

🖼️ Output Behavior:


Background becomes light gray.
Font changes to Arial.
Heading is green.

🔎 Use Case:
Best practice for styling modern websites.
Allows reuse of styles across multiple pages.
Makes styles easier to maintain and update.
Method Placement Best for
Inline In the tag (style="...") Quick, one-off styles
Internal In <style> in the <head> Small or single-page sites
External In a .css file Large projects, reusability & maintainability

🔐 External CSS is the most recommended method for scalability and clean code.
Try It Yourself

Try It Yourself


Output: