To link an external CSS stylesheet to an HTML document, you can use the <link> element in the <head> section of your HTML document. Here's how you can do it:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your HTML Document Title</title>
<!-- Linking an external CSS stylesheet -->
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- Your HTML content goes here -->
</body>
</html>
In the example above:
- <link> is the HTML element used to link external resources to an HTML document.
-
The
rel
attribute specifies the relationship between the current document and the linked resource. In this case,stylesheet
indicates that the linked resource is a stylesheet. -
The
href
attribute specifies the path to the external CSS file. You need to provide the path to your CSS file relative to the location of your HTML file. In the example above,styles.css
is the name of the external CSS file.
Ensure that the path specified in the href
attribute is correct and that the CSS file exists in the location you've specified. Once linked, the styles defined in the external CSS file will be applied to the HTML document.