Open In App

How to include External CSS in an HTML Document ?

Last Updated : 23 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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>
  
    <!-- Include external CSS -->
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
  
<body>
    <!-- Your HTML content goes here -->
</body>
  
</html>



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads