CSS (Cascading Style Sheets) is a styling language used to control the presentation and layout of HTML documents. It allows web developers to define the appearance of web pages, including elements such as colors, fonts, spacing, and positioning. Here’s an introduction to CSS:
/* Selects all <p> elements */
p { color: blue; }
/* Selects elements with class "highlight" */
.highlight { background-color: yellow; }
/* Selects an element with ID "header" */
#header { font-size: 24px; }
/* Sets the font size to 16 pixels */
font-size: 16px;
/* Sets the text color to red */
color: red;
/* Sets the background color to light gray */
background-color: lightgray;
blue
or italic
, or numerical units, such as 10px
or 2em
.Example:
/* Sets the font family to Arial */
font-family: Arial;
/* Sets the border width to 2 pixels */
border-width: 2px;
/* Sets the margin to 10 pixels on all sides */
margin: 10px;
/* Selector */
p { /* Declaration */ color: blue; }
.css
files and linked to HTML documents using <link>
elements.<style>
tags in the <head>
section of HTML documents.style
attribute.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
/* Internal Stylesheet */
h1 { color: blue; font-size: 24px; }
.highlight { background-color: yellow; } </style>
</head>
<body>
<!-- Inline Style -->
<p style="font-family: Arial;">This is a paragraph.</p>
<!-- External Stylesheet -->
<p class="highlight">This is another paragraph.</p>
<!-- Heading with Internal Stylesheet -->
<h1>Welcome to CSS</h1>
</body>
</html>
In summary, CSS is a powerful language that allows you to control the visual presentation of HTML documents. By applying styles to HTML elements using selectors and declarations, you can create attractive and responsive web pages.