- What is CSS?
- How to Include CSS
- Selectors, Properties, and Values
- Colors
- Text and Fonts
- The Box Model
- Flexbox and Grid
- Media Queries
- Further Reading
CSS stands for Cascading Style Sheets. If HTML is the skeleton of a website, think of CSS as the skin and clothes. It makes your website look pretty! 🌈
There are three main ways to include CSS in your HTML files:
You can include CSS directly in your HTML tags using the style
attribute.
<p style="color: red;">This is a red paragraph.</p>
You can include CSS in the <head>
section of your HTML file using the <style>
tag.
<head>
<style>
p {
color: red;
}
</style>
</head>
You can link to an external .css
file using the <link>
tag.
<head>
<link rel="stylesheet" href="styles.css">
</head>
In CSS, we use selectors to target HTML elements and apply styles to them.
/* This is a comment */
p {
color: red; /* This is a property and value */
}
- Selector:
p
- Property:
color
- Value:
red
Colors can be defined in various ways:
- Named colors:
red
,blue
,green
- Hex codes:
#FF0000
,#0000FF
- RGB:
rgb(255, 0, 0)
p {
color: #FF0000;
}
You can style text using properties like font-family
, font-size
, and text-align
.
p {
font-family: 'Arial';
font-size: 16px;
text-align: center;
}
Every HTML element is a box. The box model includes:
- Content
- Padding
- Border
- Margin
div {
padding: 10px;
border: 2px solid black;
margin: 20px;
}
Flexbox and Grid are modern layout models in CSS.
.container {
display: flex;
justify-content: center;
align-items: center;
}
.container {
display: grid;
grid-template-columns: 1fr 1fr;
}
Media queries allow you to apply styles based on device characteristics.
@media (max-width: 600px) {
p {
font-size: 14px;
}
}
Ready to dive deeper? Check out these free resources: