gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
how do i link a stylesheet in html
- User
how do i link a stylesheet in html
- Assistant
To link a stylesheet (CSS file) in an HTML document, you use the
<link>tag within the<head>section of your HTML. Here's a basic example of how to do this:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Your Document Title</title> <link rel="stylesheet" href="styles.css"> <!-- Link to your stylesheet --> </head> <body> <h1>Hello, World!</h1> </body> </html>Breakdown of the
<link>tag attributes:rel: Specifies the relationship between the current document and the linked resource. For stylesheets, this should bestylesheet.href: Specifies the URL of the linked resource, which is the path to your CSS file. Ensure that the path is correct relative to the HTML file's location.
Notes:
- Make sure the path to
styles.cssis correct. It can be either a relative path (like if the file is in the same directory as your HTML file) or an absolute path (a full URL).