To link to an external CSS file from an HTML document, you can use the <link>
element in the <head>
section of the HTML document. The <link>
element has three attributes: href
, rel
, and type
.
The href
attribute specifies the location of the external CSS file, the rel
attribute specifies the relationship between the HTML document and the external CSS file, and the type
attribute specifies the type of the linked document.
Here is an example of how to link to an external CSS file:
<!DOCTYPE html>
<html>
<head>
<link href="styles.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1>Welcome to my website!</h1>
<p>This is an example of how to link to an external CSS file.</p>
</body>
</html>
In this example, the href
attribute is set to "styles.css"
, which specifies the location of the external CSS file in the same directory as the HTML document. The rel
attribute is set to "stylesheet"
, which specifies that the linked document is a stylesheet. The type
attribute is set to "text/css"
, which specifies the MIME type of the linked document.
Make sure that the href
attribute points to the correct location of your external CSS file. If your CSS file is in a different directory, you will need to specify the correct path in the href
attribute.