YogeshChauhan . com

How to link/add CSS file to HTML Document?

in CSS & HTML on March 31, 2020

External CSS

When we use a separate file for page style (CSS) and add it to our HTML, it's called styling with an external CSS.

To use an external style sheet, add a link to it in the <head> section of the HTML page.

For example,


<head>
  <link rel="stylesheet" href="styles.css">
</head>

An external style sheet must not contain any HTML code, and must be saved with a .css extension.

For example:


body {
  background-color: green;
}

p {
  color: black;
}

Advantages

1. It helps you keep your website design and content separate.

2. An external style sheet is used to define the style for many HTML pages. 

3. It's really easy to reuse your CSS code if we have it in a separate file. Typing the same CSS style code in all pages you have is time consuming. Also, just imagine if you want to make a small color change? If you have 10 pages then you need to change the CSS code in 10 pages and if you have 100 pages then?!! So, try to link many pages to a single CSS file with the "link" tag.

4. With an external style sheet, you can change the look of an entire web site, by changing one file!

amazon

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How to Commit and Rollback Changes in SQL?SQL/MySQLHow to create a Star Ratings using CSS?CSSHow to Check If a Variable is an Integer, a Float, a Number, NaN, an Infinite or a Numeric in PHP?PHPSocial Media Colors: Sass VariablesMiscPagination in CSS with multiple examplesCSSWhere is the PHP log file located on Mac OS?PHP