How to Add a CSS File to HTML

来自freem
Lukegao1讨论 | 贡献2023年3月21日 (二) 15:53的版本 (创建页面,内容为“ To add a CSS file to an HTML document, follow these steps: 1. Create a CSS file: Create a separate file with a .css extension and save it with a name that describes the content. For example, "styles.css". 2. Link the CSS file to the HTML document: To link the CSS file to the HTML document, add the following code inside the head section of the HTML document: ```html <link rel="stylesheet" type="text/css" href="path/to/styles.css"> ``` Make sure to replace…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索


To add a CSS file to an HTML document, follow these steps:

1. Create a CSS file: Create a separate file with a .css extension and save it with a name that describes the content. For example, "styles.css".

2. Link the CSS file to the HTML document: To link the CSS file to the HTML document, add the following code inside the head section of the HTML document:

```html <link rel="stylesheet" type="text/css" href="path/to/styles.css"> ```

Make sure to replace "path/to/styles.css" with the actual file path of the CSS file.

3. Save the changes: Save both the HTML and CSS files in the same folder.

4. Verify the styling: Open the HTML document in a web browser and check if the styling is applied.

Here's an example of what the HTML code should look like with the CSS file linked:

```html <!DOCTYPE html> <html> <head> <title>My Website</title> <link rel="stylesheet" type="text/css" href="path/to/styles.css"> </head> <body> </body> </html> ```

That's it! You've successfully added a CSS file to your HTML document.