CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML. CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.
Basic Structure of CSS
CSS is made up of rules. Each rule consists of a selector and a declaration block.
selector {
propertyName1: value1;
propertyName2: value2;
}
Selector: This is the HTML element you want to style.
Declaration block: This contains one or more declarations separated by semicolons. Each declaration includes a CSS property name and a value, separated by a colon.
Example: Here’s a simple example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Example</title>
<style>
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
</style>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
In this example:
The body
selector styles the entire page’s background to be light blue.
The h1
selector changes the color of the heading to navy and adds a left margin.