CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML (including XML dialects such as SVG, MathML or XHTML). CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.
The primary purpose of CSS is to separate the content of a web page from its visual presentation. By using CSS, web developers can control the layout, colors, fonts, and overall style of a website independently of the HTML structure. This separation offers several key benefits:
CSS works by associating rules with HTML elements. These rules consist of selectors and declarations.
{}
and consist of property-value pairs, such as color: blue;
or font-size: 14px;
.Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example Page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a paragraph styled with CSS.</p>
</body>
</html>
/* styles.css */
h1 {
color: blue;
font-size: 24px;
}
p {
color: gray;
font-size: 16px;
}
In this example:
styles.css
).<h1>
and <p>
elements.