CSS (Cascading Style Sheets) is the language used to style HTML documents. It controls the layout, colors, fonts, and overall visual appearance of a web page.
A CSS rule consists of a selector and a declaration block:
selector {
property: value;
}
h1 {
color: blue;
font-size: 24px;
}
Applied directly to an element using the style attribute.
<p style="color: red;">This is red text.</p>
Written inside a <style> tag in the <head> section.
<style>
p { color: red; }
</style>
Linked via a .css file using the <link> tag. This is the recommended approach.
<link rel="stylesheet" href="styles.css">
p {
color: green;
}
.highlight {
background: yellow;
}
#header {
font-size: 2rem;
}
* {
margin: 0;
padding: 0;
}
Comments are ignored by the browser and help document your code:
/* This is a CSS comment */
h1 {
color: navy;
}
Create an HTML page with an external stylesheet. Style a <h1> with a color of your choice and a <p> with a class of intro that has a larger font size.