CSS
(Cascading Style sheet)
Cascading Style Sheets (CSS) is a styling language used to control the layout and
appearance of web pages written in HTML or XML. CSS is used to separate
presentation from structure, making it easier to maintain and update websites.
CSS Purpose:
1. Control layout: position, size, and spacing of elements
2. Apply visual styles: colors, fonts, backgrounds, and more
3. Create responsive designs: adapt to different screen sizes and devices
4. Improve accessibility: provide clear and consistent formatting
CSS Components:
1. Selectors: target specific HTML elements (e.g., .header, #nav)
2. Properties: specify styles for selected elements (e.g., color, font-size)
3. Values: assign values to properties (e.g., red, 18px)
4. Rules: combine selectors, properties, and values (e.g., .header { color: red; })
CSS Types:
1. Internal CSS: embedded within an HTML document
2. External CSS: stored in a separate file (recommended)
3. Inline CSS: applied directly to an HTML element (not
recommended)CSS Syntax:
CSS Syntax:
selector { property: value;
property: value;}
Example CSS:
body { background-color: #f2f2f2;
font-family: Arial, sans-serif;}
.header { color: #00698f;
padding: 20px;
text-align: center;}
CSS Best Practices:
1. Use meaningful class names
2. Avoid inline styles
3. Use external CSS files
4. Minimize CSS complexity
5. Test for browser compatibility