CSS
CSS Introduction
What is CSS ?
CSS (Cascading Style Sheets) is a stylesheet language used to control the presentation and layout of HTML elements on a webpage. It allows developers to separate content (HTML) from design (CSS), making it easier to maintain and update webpages.
Types of CSS
Inline CSS: Written directly inside an HTML element.
Internal CSS: Written within <style>
tags inside the HTML head section.
External CSS: Written in a separate file, linked in HTML.
CSS Cascade & Specificity
When multiple CSS rules apply to the same element, CSS decides which styles take priority using the cascade.
Order of precedence (highest to lowest):
- Inline styles (style attribute).
- Internal & external styles (in
<style>
or external files), determined by specificity. - Browser default styles.
Specificity (strongest to weakest):
- ID Selector (#id)
- Class Selector (.class)
Advantages of CSS:
- Simplifies website design and maintenance.
- Increases site loading speed.
- Provides consistent look across multiple webpages.
- Makes responsive web design achievable.