Web Learning - Understanding Basic Concepts
Last updated on April 9, 2026 pm
This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to original Chinese version. I am continuously working to improve the translation.
Preface to the Preface
I've wanted to learn frontend for a long time, so today I'm starting this project. I'll try to speed-run the basics of HTML + CSS + JS/TS within this week, and then learn Vue next week.
References:
Preface
What happens when a user visits a website?
- A web page is essentially a file
- When accessing a website through a browser,
- The browser sends a request to the server
- The server then sends the web page file to the browser
- The browser then renders the web page file into the page we see.
Here, let's distinguish three easily confused concepts:
- Web Pages
- A document that can be displayed in a web browser
- Written in the HTML language
- Website
- A collection of many web pages grouped together, sharing a unique domain name
- Web Server
- A computer that hosts a website on the internet
Web Pages / Overview of Web Technologies
HTML
HTML (Hyper Text Markup Language) is a language used to describe web page documents.
A core element/feature of HTML is tags; HTML defines many different tags.
- Tags are wrapped in angle brackets
<> - Opening tags and closing tags usually appear in pairs
- A closing tag is based on the opening tag, with a
/added after the< - Tags themselves indicate the type and format of the content
- Tags wrap the actual content
As a simple example, the following code represents a bold Hello
<b>Hello</b>Here are some commonly used HTML tags for representing text:
| Tag | Description |
|---|---|
<h1> - <h6> |
Defines headings, from the highest level to the lowest |
<p> |
Defines a paragraph |
<ul> |
Defines an unordered list |
<ol> |
Defines an ordered list |
<li> |
Defines a list item |
<table> |
Defines a table |
<tr> |
Defines a table row |
<td> |
Defines a table cell |
<th> |
Defines a table header cell |
<strong> |
Defines bold text |
<em> |
Defines italic text |
<br> |
Inserts a line break |
The above is all copied, since this article is just an introduction to most of this knowledge.
The "Hyper" in HTML means that HTML tags can also represent content beyond text. Here are some other commonly used tags:
| Tag | Description |
|---|---|
<html> |
Defines the root element of an HTML document |
<head> |
Defines the head area of the document |
<body> |
Defines the body area of the document |
<img> |
Inserts an image |
<a> |
Creates a link |
<div> |
Defines a block or container |
<span> |
Marks or wraps a text fragment |
<header> |
Defines the header section |
<style> |
Defines an internal style sheet |
Of course, this is also copied
Here is an example of a simple HTML document:
<!DOCTYPE html>
<!--声明文档类型-->
<!--没错,这就是注释的写法-->
<html>
<head>
<title>Tab 栏标题</title>
</head>
<body>
<h1>大标题</h1>
<p>一个段落包含一部分<b>加粗的文字</b></p>
<img src="./figure.png">
<!--一张图片-->
<a href="https://net9.org/">链接</a>
<!--一个超链接-->
</body>
</html>CSS
We can use CSS (Cascading Style Sheets) to add styles to web pages.
For example, you can add a style="..." attribute inside an opening tag for styling, or add a <style>...</style> tag in the document head to define styles for batch formatting adjustments.
代码
<!DOCTYPE html>
<!--声明文档类型-->
<html>
<head>
<title>Tab 栏标题</title>
<style>
h1 {
color: darkgray;
font-weight: bold;
}
</style>
<!--定义了 h1 标签的颜色和字体-->
</head>
<body>
<h1>大标题</h1>
<p style="color: deepskyblue">一个段落包含一部分<b>加粗的文字</b></p>
<!--剩余部分同上-->
</body>
</html>belike:
Tab bar title A big heading
A paragraph containing somebold text
Different pages of the same website often share a consistent format, and making repeated modifications in every HTML file is rather cumbersome. Therefore, these styles can be extracted into a separate CSS file.
For example, the following CSS code selects all paragraph text and sets it to red:
h1 {
color: red;
font-size: 2em;
}h1 is called a selector, and what's wrapped inside {} are multiple declarations, each consisting of a property and a value. A CSS style sheet usually contains many such rules, written one after another.
CSS can control styles not only by element type, but also supports many more style controls.
It's called a "Cascading Style Sheet" because when multiple rules apply to the same element, the rules are layered in a certain order — you can think of different rules as having different priorities. For example, a style written directly inside an HTML tag, <style>, will override a separately referenced external CSS file.
JavaScript
Purely static web pages are too boring; we can use a scripting language like JavaScript to implement interactivity in web pages.
JavaScript code can be embedded directly in a web page, or written as a separate file.
JS is a scripting language that requires no compilation; once embedded in HTML, it can run directly.
Advantages: it can conveniently access the network and manipulate elements in HTML.
Browser Developer Tools
Pressing F12 lets you read the HTML, CSS, and JS source code of a web page, modify HTML and CSS, and enter JS code for debugging.
Web Communication
What is HTTP?
HTML, CSS, and JavaScript are collectively known as the "frontend trio". If we compare these files to packages, then to achieve communication, we also need a "courier" — the HTTP protocol.
The HTTP (Hyper Text Transfer Protocol) is an application-layer protocol used for transferring hypertext, and it is based on the TCP/IP protocol.
When sending a request, we may want to obtain some files, or we may need to actively send some information, such as usernames and passwords. The HTTP protocol defines a set of request methods, which won't be covered in detail here.
After a request sent by the client is received by the server, the server processes it and returns a response, which includes:
- A status code
- Response headers
- A response body, etc.
The status code indicates the status of the request, such as the well-known 404 Not Found.
What files are included in an HTTP response?
- HTML files
- CSS files
- JS files
- Media resources and other types of files
The Web Page Rendering Process
When a user visits a web page, the browser sends multiple HTTP requests and then receives multiple files from the HTTP responses. The browser then processes these files and assembles them into an interactive web page — this process is called rendering.
Let's understand the rendering process step by step.
Processing HTML
After receiving the HTML file, the browser parses it into a DOM tree (Document Object Model).
The DOM represents the hierarchical relationships of the entire HTML file in memory as a tree structure. For example:
<p>
Let's use
<span>HTML</span>
<span>CSS</span>
<span>JavaScript</span>
</p>Every tag, attribute, and piece of text becomes a DOM node in the DOM tree:
P
├─ "Let's use:"
├─ SPAN
| └─ "HTML"
├─ SPAN
| └─ "CSS"
└─ SPAN
└─ "JavaScript"During HTML parsing, if the browser encounters
- An external CSS file referenced by
<link> - An external JS file referenced by
<script> - Other external resources such as
<img>and<video>
it will initiate additional HTTP requests to fetch the external resources.
Parsing CSS and Rendering the Page
The browser processes CSS according to these steps:
- Parse all CSS on the page, including the
<style>embedded in HTML as well as external references, and based on the HTML elements the styles apply to, place the CSS style rules into different "buckets", then attach the styles to the corresponding elements as needed, forming the render tree. - Present the structure that the render tree should display after the rules are applied
- Actually display the laid-out nodes on the screen
Processing JavaScript
After the CSS is processed, any JS code on the page is parsed, interpreted, compiled, and executed.
Web Application Basics
Static Web Pages
Some websites have content that is created in advance and remains fixed; these are called static web pages, such as personal blog sites generated by Hexo.
For static web pages, each address corresponds to a fixed web page file, and the server only needs to send the content to the client (the requester).
However, some web pages' content has to change dynamically — the content needs to be updated in real time, or we want to display different content based on the user's identity. In such cases, dynamic web pages are needed.
Dynamic Web Pages
Dynamic web page content is generated dynamically based on the user's request.
The traditional strategy for implementing dynamic web pages:
- The server receives the request and reads data from the database
- The data is filled into a pre-prepared template to form a complete HTML file
- The file is sent to the client
However, this pattern requires sending the complete HTML file every time, consuming a large amount of network traffic and reducing transmission efficiency.
The modern approach: separate the "dynamic" data from the "static" template, and let the client complete the process of filling the data into the template. This is the frontend-backend separation development model.
The Frontend-Backend Separation Development Model
-
The dynamic part: the actual data
-
The static part: the web page's framework, the interface presented to the user
-
Frontend: the user interface
-
Backend: data and business logic
The JS script on the web page sends requests to the designated backend server, and the JS script fills the retrieved information into the web page, presenting the content the user sees.
Communication between the frontend and backend also typically uses the HTTP protocol; the format of the content is specified by the developers and is called an API (Application Programming Interface).
Web Best Practices
Since we don't know the user's platform, we need to practice defensive design.
The Web always requires backward compatibility.
Web design involves cross-browser compatibility.
Responsive layout: a practice that makes functionality and layout flexible, allowing web pages to adapt to different browsers. A typical example: a website that is laid out one way in a wide-screen desktop browser, but in a different, more compact single-column layout in a mobile browser.