How to Add a CSS File to HTML

来自freem
跳到导航 跳到搜索


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.