1. HTML and CSS: A Partnership
The web relies on two languages working together:
- HTML (HyperText Markup Language): Provides the structure and content (the nouns and verbs). It defines paragraphs, headings, images, and links.
- CSS (Cascading Style Sheets): Provides the presentation and styling (the adjectives and adverbs). It controls the colors, fonts, layout, and visual appearance of the HTML elements.
Analogy: HTML is the skeleton of the house; CSS is the paint, furniture, and landscaping.
2. Setting Up Your Code Editor
To write and manage code efficiently, you need a robust text editor.
- Recommendation: Visual Studio Code (VS Code)
- VS Code is a powerful, free, and highly customizable code editor used by professionals. It offers features like syntax highlighting, intelligent code completion (IntelliSense), and integrated debugging tools.
📝 Project Folder Structure
Start every project with a clear, organized structure:
my-css-project/
├── index.html <-- Your main content file
└── css/
└── styles.css <-- Your styling rules
3. Running Code Locally
You don’t need a server to view your HTML and CSS; your web browser can render them directly from your file system.
A. Basic Workflow
- Create the
index.htmlfile and thestyles.cssfile. - Open the
index.htmlfile directly in your browser (e.g., drag and drop the file, or use File $\rightarrow$ Open in the browser).
B. Using Live Server (Recommended)
To streamline development, use the Live Server extension in VS Code:
- Install the Live Server extension (by Ritwick Dey) from the VS Code Extensions panel.
- Open your
index.htmlfile in VS Code. - Right-click anywhere in the editor and select “Open with Live Server”.
This automatically launches your page in a browser and reloads the page instantly every time you save a change to your HTML or CSS file, saving you time.
4. Integrating CSS into HTML
Before you write CSS, you must link your stylesheet to your HTML document. The best practice is to use an External Stylesheet linked in the <head> section of your HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First CSS Project</title>
<link rel="stylesheet" href="css/styles.css">
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
- The
rel="stylesheet"attribute tells the browser that this linked file contains styling rules. - The
hrefattribute must point to the correct path of your.cssfile.
5. Debugging with Developer Tools
The most important tool for learning CSS is the browser’s Developer Tools (often called DevTools).
- How to Open: Press F12 or Ctrl+Shift+I (Windows/Linux) / Cmd+Option+I (Mac).
- The Styles Panel:
- Click the “Inspect” element tool (usually an arrow icon).
- Click any element on your webpage.
- The Styles Panel will show you all the CSS rules applied to that element, including which file and line number they came from.
- You can live-edit the CSS properties here to test changes without saving the source file (changes disappear on refresh).
Now that your local environment is set up, we can move into the language fundamentals.
