0
0
Angularframework~20 mins

Inline vs external styles in Angular - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Angular Styles Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
How does Angular apply inline styles compared to external styles?

Consider an Angular component with both inline styles defined in the @Component decorator and external styles linked via styleUrls. What is the behavior of Angular when rendering these styles?

Angular
@Component({
  selector: 'app-sample',
  template: `<p class='text'>Hello</p>`,
  styles: [`.text { color: red; }`],
  styleUrls: ['./sample.component.css']
})
export class SampleComponent {}
AAngular applies only external styles and discards inline styles defined in the component decorator.
BAngular ignores inline styles if external styles are present in styleUrls.
CAngular applies only inline styles and ignores external styles in styleUrls.
DAngular merges inline styles and external styles, applying both with inline styles taking precedence if conflicts exist.
Attempts:
2 left
💡 Hint

Think about how CSS specificity and Angular style encapsulation work together.

📝 Syntax
intermediate
2:00remaining
Identify the correct way to add inline styles in Angular component

Which of the following Angular component decorators correctly applies inline styles?

A@Component({ selector: 'app-test', template: `<div>Test</div>`, styles: ['div { color: blue; }'] })
B@Component({ selector: 'app-test', template: `<div>Test</div>`, styleUrls: ['div { color: blue; }'] })
C@Component({ selector: 'app-test', template: `<div>Test</div>`, styles: 'div { color: blue; }' })
D@Component({ selector: 'app-test', template: `<div>Test</div>`, style: ['div { color: blue; }'] })
Attempts:
2 left
💡 Hint

Remember the property name for inline styles is plural and expects an array.

🔧 Debug
advanced
2:00remaining
Why does external style not apply in this Angular component?

Given this Angular component, the external CSS file app.component.css contains p { font-weight: bold; } but the paragraph text is not bold. What is the likely cause?

Angular
@Component({
  selector: 'app-root',
  template: `<p>Important text</p>`,
  styleUrls: ['./app.component.scss']
})
export class AppComponent {}
AThe external style file path is incorrect or the file does not exist at the specified location.
BThe external style file has a wrong extension (.scss) but Angular expects .css and does not process it.
CAngular disables external styles by default and requires inline styles only.
DThe paragraph tag is missing a class, so styles do not apply.
Attempts:
2 left
💡 Hint

Check the file path and file existence carefully.

state_output
advanced
2:00remaining
What is the color of the text rendered by this Angular component?

Consider this Angular component with conflicting inline and external styles. What color will the paragraph text be?

Angular
@Component({
  selector: 'app-color',
  template: `<p class='text'>Color Test</p>`,
  styles: [`.text { color: green !important; }`],
  styleUrls: ['./color.component.css']
})
export class ColorComponent {}
ARed, because inline styles are ignored and external styles set color to red.
BGreen, because inline styles with !important override external styles.
CBlack, because Angular does not apply styles with !important.
DBlue, because the external CSS file sets .text { color: blue; } and !important is ignored.
Attempts:
2 left
💡 Hint

Recall how CSS !important affects style precedence.

🧠 Conceptual
expert
3:00remaining
Why prefer external styles over inline styles in Angular for large projects?

In large Angular projects, why is it generally better to use external stylesheets (styleUrls) instead of inline styles (styles)?

AAngular does not support inline styles in production builds, so external stylesheets are mandatory.
BInline styles are faster to load, so external stylesheets are avoided for performance reasons.
CExternal stylesheets improve maintainability and caching, while inline styles increase component size and reduce reuse.
DExternal stylesheets disable Angular's style encapsulation, which is preferred in large projects.
Attempts:
2 left
💡 Hint

Think about how code organization and browser caching affect large apps.