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
Start learning this pattern below
Jump into concepts and practice - no test required
/* 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.
Practice
style attribute?Solution
Step 1: Understand CSS placement types
Inline CSS is applied directly inside an HTML element using thestyleattribute.Step 2: Match the description to the type
Since the question asks for CSS inside the tag, this matches Inline CSS.Final Answer:
Inline CSS -> Option BQuick Check:
CSS inside tag = Inline CSS [OK]
- Confusing internal CSS with inline CSS
- Thinking external CSS is inside the tag
- Mixing embedded CSS term with inline
Solution
Step 1: Identify internal CSS syntax
Internal CSS uses a<style>tag placed inside the<head>section.Step 2: Check each option
<style> p { color: blue; } </style>inside the<head>section correctly uses<style>with CSS inside<head>. Others misuse tags or placement.Final Answer:
<style> p { color: blue; } </style> inside the <head> section -> Option AQuick Check:
Internal CSS = <style> in <head> [OK]
- Placing <link> inside body for internal CSS
- Using <script> tag for CSS
- Using <style> with src attribute
<head>
<style>
p { color: red; }
</style>
</head>
<body>
<p style="color: blue;">Hello World</p>
</body>Solution
Step 1: Identify CSS types and priority
The paragraph has internal CSS setting color red and inline CSS setting color blue.Step 2: Understand CSS specificity
Inline CSS has higher priority than internal CSS, so the color blue applies.Final Answer:
Blue -> Option CQuick Check:
Inline CSS overrides internal CSS [OK]
- Thinking internal CSS overrides inline
- Assuming default color applies
- Ignoring CSS specificity rules
<head>
<link rel="stylesheet" href="styles.css">
<style>
body { background-color: white; }
</style>
</head>Solution
Step 1: Check <link> tag syntax
In HTML5, <link> is a void element and does not require a self-closing slash. <link rel="stylesheet" href="styles.css"> is valid.Step 2: Verify other elements
The <style> tag is correctly placed inside <head>. File name and everything else is fine. No errors.Final Answer:
No error, code is correct -> Option DQuick Check:
<link> without / is valid HTML5 [OK]
- Thinking <link> requires closing slash
- Thinking <style> should be outside <head>
- Assuming file name error without checking
Solution
Step 1: Understand CSS reuse and overrides
External CSS is best for common styles shared across pages for easy maintenance.Step 2: Use inline CSS for specific overrides
Inline CSS can override external styles on a single element for page-specific changes.Final Answer:
Use external CSS for common styles and inline CSS for page-specific overrides -> Option AQuick Check:
External CSS + inline overrides = best practice [OK]
- Using only inline CSS everywhere (hard to maintain)
- Avoiding overrides when needed
- Using internal CSS on every page (redundant)
