1. Introduction to the Web
How websites work
Websites operate through a request-response cycle. When you enter a URL, your browser sends an HTTP request to a server, which processes the request and sends back files.
The browser then interprets these files to render the visual interface. This cycle is the fundamental building block of the internet experience.
Client Request -> Internet/DNS -> Server Response -> Rendering
Client vs Server
The client refers to the user's browser or device, which handles the frontend interface. The server is the remote computer that stores data and processes logic.
The server sends raw assets like files to the client, while the client reconstructs them into a navigable web page.
Browser (Client) <--- Request/Response ---> Web Server
Browsers and Rendering
Browsers act as an interface layer that parses HTML, CSS, and JavaScript. The engine converts these instructions into a Document Object Model (DOM).
Modern browsers follow W3C standards to ensure consistency, though engines like Chromium or Gecko may handle complex layout calculations slightly differently.
Source Code -> DOM Tree -> CSSOM Tree -> Render Tree -> Painting
HTML
The <html> element is the root of the document, but content resides in semantic tags like <main>, <article>, and <header>. HTML provides the structure of the document.
Using semantic tags helps screen readers navigate your content and boosts SEO, making your structure clear to search engine crawlers.
<div> tags to improve accessibility.
<main> <h1>Welcome</h1> <p>Content goes here.</p> </main>
CSS
CSS is used to style elements and manage layout. By selecting elements with tags or classes, you apply properties that determine appearance.
Separating CSS from HTML keeps your code clean and allows you to update the look of your entire site from one central stylesheet.
.container { display: flex; color: #333; }
JavaScript roles
JavaScript provides interactivity. It can manipulate the DOM, fetch data from servers asynchronously, and handle user events.
While HTML and CSS are static, JavaScript brings pages to life, allowing for complex UI behaviors and data-driven updates.
defer attribute to avoid blocking page rendering.
document .querySelector('button') .addEventListener('click', () => alert('Hello!'));
<!-- Try it: defer --> <script src="app.js" defer></script> <script src="analytics.js" async></script>
Setting up VS Code
VS Code is a powerful editor that provides intellisense, error highlighting, and extensibility. It is the industry standard for web development.
Configuration is straightforward; once installed, you can optimize your workspace by installing extensions that automate repetitive tasks.
Settings -> Extensions -> Install 'Live Server'
Installing Live Server
Live Server is a VS Code extension that launches a local development server with a live reload feature. Every time you save a file, the browser updates automatically.
This tool eliminates the need to manually refresh the browser after every minor code change, significantly speeding up the development workflow.
Go to Extensions icon -> Search 'Live Server' -> Click Install
Folder structure
A standard project folder separates concerns by keeping styles in a css directory and scripts in a js directory.
Consistent folder structures make it easier to manage large projects and ensure assets like images and fonts are correctly linked.
./css/style.css) to ensure your project works when moved to a different folder.
/project-root/index.html /css/style.css /js/main.js /assets/logo.png
Knowledge Check
Ready to test your understanding of 1. Introduction to the Web?