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!

dreamhost

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 uninstall Cocoapods from the Mac OS? #4 How to add Read More Read Less Button using JavaScript? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

May 5 Use inline if to make a shorter conditional syntax in React May 4 What is Conditional Rendering in React? May 3 How does @extend rule work in SCSS (Sass)? May 2 How different is Handling Events in React vs HTML DOM? May 2 How to create bouncing balls using HTML canvas and JavaScript? Apr 30 HTML canvas methods

You might also like these

Why it’s not a good idea to create Number objects in JavaScript?JavaScriptHow to create a link tag button using CSS?CSSWhat is Conditional Rendering in React?ReactHow to change CSS with jQuery?CSSHow to use HTML picture Tag?HTMLHow to create a smooth scrolling effect with CSS?CSS