What if your styles never accidentally broke other parts of your app again?
Why Component styles and encapsulation in Angular? - Purpose & Use Cases
Imagine building a website where you have to style every button, header, and card manually by writing CSS that affects the whole page. If you change one style, it might accidentally change other parts you didn't want to touch.
Manual global CSS is like painting a wall without tape--you risk spilling paint everywhere. Styles can clash, override each other, and become hard to track. This makes your app fragile and frustrating to maintain.
Component styles and encapsulation in Angular keep styles local to each component. This means your button styles won't leak out and affect other parts of the page, making your app easier to build and safer to change.
button { color: red; } /* affects all buttons everywhere */:host button { color: red; } /* styles only this component's buttons */This lets you build reusable, independent components that look and behave consistently without style conflicts.
Think of a dashboard with many widgets. Each widget can have its own style without breaking the look of others, even if they use similar elements like buttons or headings.
Global CSS can cause unexpected style conflicts.
Component styles keep styles local and safe.
Encapsulation helps build reusable, maintainable UI parts.