Introduction
CSS syntax and rules tell the browser how to style your webpage. They help you change colors, sizes, and layout in a clear way.
Jump into concepts and practice - no test required
selector {
property: value;
property2: value2;
}p {
color: blue;
}h1 {
font-size: 2rem;
margin-bottom: 1rem;
}.button { background-color: green; padding: 0.5rem 1rem; }
#main { display: flex; gap: 1rem; }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>CSS Syntax Example</title> <style> body { font-family: Arial, sans-serif; background-color: #f0f0f0; margin: 2rem; } h1 { color: #2a7ae2; font-size: 2.5rem; margin-bottom: 1rem; } p { color: #333333; font-size: 1.125rem; line-height: 1.5; } .highlight { background-color: #fff3b0; padding: 0.5rem; border-radius: 0.25rem; } </style> </head> <body> <h1>Welcome to CSS</h1> <p>This is a simple paragraph styled with CSS.</p> <p class="highlight">This paragraph has a highlighted background.</p> </body> </html>
color: blue; with a colon and semicolon ending the statement.p { color: red; color: green; }color: red; first, then color: green; which overrides red.h1 { font-size 20px; }font-size must be followed by a colon before the value.section p targets all p elements inside any section.