How to include External CSS in an HTML Document ?
Last Updated :
23 Jan, 2024
Adding External CSS in an HTML document is achieved using the <link>
element in the <head>
section. This approach allows you to separate your HTML content and styling. Here are some important points:
- Establishing Connection (rel attribute): The <link> element uses the “rel” attribute to show how the HTML document is connected to the linked thing.
- Identifying Resource Type (type attribute): The “type” attribute specifies what kind of data is linked. For CSS files, it’s set to “text/css,” telling that it’s a style sheet.
- Locating the File (href attribute): The href attribute holds the address or web link to the external CSS file. Make sure it accurately points to where your CSS file is located.
Syntax
<link rel="stylesheet" type="text/css" href="styles.css">
Example: Implementation to show the addition of external CSS.
HTML
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
< title >External CSS Addition</ title >
< link rel = "stylesheet" type = "text/css" href = "styles.css" >
</ head >
< body >
</ body >
</ html >
|
Share your thoughts in the comments
Please Login to comment...