To attach an external CSS document to a web page, the <link> element is used within the <head> section of the HTML document.
<link> Element:
Purpose: Links external resources, such as stylesheets, to the HTML document.
Attributes:
rel="stylesheet": Specifies the relationship between the current document and the linked resource.
href="path/to/stylesheet.css": Specifies the URL of the external stylesheet.
Example:
<head>
<link rel="stylesheet" href="styles.css">
</head>
Other Options:
<style>: Used to embed internal CSS directly within the HTML document, not for linking external CSS.
<script>: Used to embed or link to JavaScript files.
<meta>: Provides metadata about the HTML document, not for linking stylesheets.
References:
W3C HTML5 Specification - The link element
MDN Web Docs - <link>
By using the <link> element correctly, you can ensure that your web page is styled with external CSS, maintaining a separation of concerns and making your HTML more manageable.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit