HTML Styles ā CSS
Subject: html
HTML Styles ā CSS
CSS (Cascading Style Sheets) is used to style and layout HTML documents. It enables developers to apply colors, fonts, spacing, alignment, and responsive designs efficiently.
šØ CSS = Styling, Fonts, Colors, Layout
With CSS, you can:
- Set colors for text and backgrounds
- Control font type, size, and style
- Adjust spacing between elements
- Create borders, margins, and padding
- Align elements and format layout across devices
š What is CSS?
CSS separates content (HTML) from presentation (CSS), making web pages more maintainable and scalable.
Note: "Cascading" means styles applied to parent elements are inherited by child elements unless overridden.
Example:
š Ways to Apply CSS
1. Inline CSS
Applied directly inside HTML elements via the style
attribute.
ā Quick but hard to maintain for large projects.
2. Internal CSS
Defined inside a <style>
tag in the HTML <head>
.
3. External CSS
Linked from an external .css
file, best for maintaining larger websites.
ā Highly recommended for scalability and reuse.
š§ Common CSS Properties & Examples
1. color
Sets the text color.
2. font-family
Sets the font style.
3. font-size
Sets the size of the text.
4. background-color
Sets background color.
5. border
Applies border to elements.
6. padding
Controls spacing inside elements.
7. margin
Controls spacing outside elements.
8. text-align
Aligns text within the element.
9. width
& height
Defines size of an element.
10. display
Defines element display behavior.
āļø CSS Specificity and Priority
CSS rules follow a hierarchy:
- Inline Styles > Internal Styles > External Styles
Specificity Score:
- ID selectors > Class selectors > Element selectors
- When multiple rules apply, the last declared rule with the highest specificity wins.
ā Key Takeaways
- Use CSS to control layout and appearance across pages.
- Inline CSS: single elements
- Internal CSS: one-page styles
- External CSS: full website styling
- Master properties like
color
,font-family
,margin
,padding
,border
, anddisplay
. - Understand specificity to resolve styling conflicts and ensure maintainable code.
Advertisement Slot 1
Advertisement Slot 2