CSS Basics Cheat Sheet
CSS Syntax
CSS is used to style and layout web pages. The basic structure of a CSS rule is:
selector {
property: value;
}
Example:
p {
color: blue;
font-size: 16px;
}
Common CSS Properties
Here are some common CSS properties:
- color: Text color
- background: Background color or image
- font-size: Size of the text
- margin: Space outside the element
- padding: Space inside the element
- border: Border around the element
- width/height: Set size of elements
Ways to Apply CSS
There are three ways to apply CSS to HTML elements:
1. Inline CSS
<p style="color: red;">Hello</p>
2. Internal CSS
<style>
p { color: red; }
</style>
3. External CSS
<link rel="stylesheet" href="styles.css">
Examples
Here are a few examples with code snippets:
/* Example 1: Styling a paragraph */
p {