CSS (Cascading Style Sheets) is a stylesheet language used to style HTML elements — change colors, fonts, sizes, layouts, and responsiveness.
<p style="color: red;">This is red text.</p>
<style>
p {
color: green;
}
</style>
HTML:
<link rel="stylesheet" href="style.css">
style.css:
p {
color: blue;
}
selector {
property: value;
}
Example:
h1 {
color: red;
font-size: 30px;
}
p {
color: purple;
}
.box {
border: 1px solid black;
}
<div class="box">I am a box</div>
#header {
background-color: yellow;
}
h1, h2, p {
color: blue;
}
color: red;
color: #ff0000;
color: rgb(255, 0, 0);
body {
font-family: Arial, sans-serif;
font-size: 16px;
font-weight: bold;
text-align: center;
text-transform: uppercase;
}
.box {
width: 300px;
height: 100px;
padding: 20px;
margin: 30px;
border: 2px solid black;
background-color: lightblue;
}
span { display: inline; }
div { display: block; }
.flex-container {
display: flex;
justify-content: space-between;
align-items: center;
}
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.box {
position: relative;
top: 20px;
left: 10px;
}
Include this in your <head>:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Media Query Example:
@media (max-width: 768px) {
body {
background-color: pink;
}
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1 id="main-title">Welcome</h1>
<p class="intro">CSS Example</p>
<div class="box">Box</div>
</body>
</html>
body {
background: #f4f4f4;
font-family: sans-serif;
}
#main-title {
color: teal;
text-align: center;
}
.intro {
font-size: 18px;
color: navy;
}
.box {
width: 300px;
margin: 20px auto;
padding: 20px;
background-color: orange;
text-align: center;
}