How the Web Works (Browser, Server, HTTP)
The web is a client-server model. Think of it like ordering food at a restaurant.
-
Client (Browser - Chrome, Firefox, Safari): You, the diner. You place an order (request) and consume the meal (render the response). The browser's job is to send requests and display the code it receives (HTML, CSS, JavaScript) as a visual webpage.
-
Server (Computer that hosts a website): The kitchen and chef. It listens for orders and sends back the files (the meal).
-
HTTP (Hypertext Transfer Protocol): The language or rules of the order. It’s the set of rules governing the conversation.
-
Request: What the browser sends.
-
Method:
GET(I want to see this page),POST(I want to submit this form). -
URL: The address (e.g.,
https://www.example.com/about). -
Headers: Extra info (e.g., "I accept English", "I am using Chrome").
-
-
Response: What the server sends back.
-
Status Code: Did it work?
-
200 OK: Success!
-
404 Not Found: The page doesn't exist.
-
500 Internal Server Error: The kitchen (server) is broken.
-
-
Body: The actual files (HTML, CSS, images).
-
-
Key Concept: When you type a URL and press Enter, the browser finds the server (via DNS), sends a GET request, waits for the 200 OK response containing HTML, and then renders that HTML on your screen.
2. Code Editors (VS Code)
Visual Studio Code (VS Code) is the industry standard because it's lightweight, free, and incredibly extensible.
Setup:
-
Download and install from code.visualstudio.com.
-
Open VS Code.
-
Open the Extensions view (click the square icon on the left sidebar or press
Ctrl+Shift+X).
Essential Extensions for Beginners:
-
Auto Rename Tag: Automatically renames the closing HTML tag when you rename an opening one.
-
Live Server: Creates a local development server with live reload. (This is crucial—it lets you see changes instantly in your browser as you save your code).
-
Prettier - Code formatter: Automatically formats your code to look clean and consistent.
Shortcuts:
-
Ctrl + S(Win) /Cmd + S(Mac): Save. -
Ctrl + /: Comment/uncomment a line. -
!+Tab(in an HTML file): Generates the basic HTML boilerplate structure.
3. Folder Structure & Best Practices
Never just save files to your desktop. A clean folder structure is essential for scalability and sanity.
Recommended Project Structure:
Create a main folder for your project (e.g., my-first-website). Inside, organize as follows:
text
my-first-website/ │ ├── index.html (The home page - must be named index.html) ├── about.html (Another page) │ ├── css/ (All stylesheets) │ └── style.css │ ├── js/ (All JavaScript files) │ └── script.js │ ├── images/ (All images) │ ├── logo.png │ └── hero-bg.jpg │ └── assets/ (Optional: fonts, other media)
Best Practices:
-
Use lowercase: Always use lowercase letters for file and folder names. Use hyphens (
-) instead of spaces (e.g.,my-profile-pic.jpg, notMy Profile Pic.jpg). -
Relative paths: When linking files, use relative paths.
-
Good:
css/style.css(links to the CSS folder from the root). -
Bad:
C:\Users\YourName\Desktop\my-first-website\css\style.css(absolute path—this will break when you upload to the internet).
-