How to connect CSS to HTML
Tags: html, css, beginners, codenewbie
Published: 2022-03-14 16:45:10

Welcome to the wonderful world of coding! In this blog post, we’ll be discussing how to connect your CSS file to your HTML file. This is an important step in creating a web page, and if you’re just starting out, it’s a good idea to get comfortable with this process. So let’s get started!

As a beginner, I was intimidated to start with CSS as quickly as I did. I had only just started with HTML, and it felt like it was too soon to start my second language. But it’s never too early. The reality is that if you learn styling in HTML, the syntax is the same. The only difference is how you format the actual code, which is why you can **[learn two programming languages at the same time](https://worldofdev.info/learn-two-programming-languages-at-once-should-you-do-it/).**

**How to connect CSS to HTML is relatively simple. All you need to do is add a `<link>` tag in the head section of your HTML file and add the location of your CSS file with a rel attribute of “stylesheet”.**

**Table Of Contents**

1. [Basic HTML Document Structure](https://worldofdev.info/how-to-connect-css-to-html-file/#basic-html-document-structure)
2. [Ways to connect CSS to HTML](https://worldofdev.info/how-to-connect-css-to-html-file/#ways-to-connect-css-to-html)
3. [How to connect CSS to HTML](https://worldofdev.info/how-to-connect-css-to-html-file/#how-to-connect-css-to-html)
4. [Why use CSS and not inline HTML styling](https://worldofdev.info/how-to-connect-css-to-html-file/#why-use-css-and-not-inline-html-styling)
5. [Conclusion](https://worldofdev.info/how-to-connect-css-to-html-file/#conclusion)

## **Basic HTML Document Structure**

If you know your **[Basic HTML Document Structure](https://worldofdev.info/basic-html-document-structure/),** you know that your document contains a `<head>` tag, and various metadata **[should be included in the `<head>` tag](https://worldofdev.info/how-to-use-the-head-tag-in-html-and-what-to-include/).** One of the items to include in your head tag is the connection to your CSS file.

The first thing you need to do is include a `<link>` tag in your `<head>` tag.

## **Ways to connect CSS to HTML**

There are a few ways to connect a CSS stylesheet to an HTML document. This article will show you the most common methods and explain how I suggest beginners connect CSS to HTML files.

The first way to connect CSS to HTML is by using the <link> element, which is placed in the `<head>` section of your HTML document. This method is most commonly used when you want to load an external CSS file. This is the method that we will give code examples for below, as it is one of the easiest ways for beginners to connect CSS to HTML.


The second way to connect CSS to HTML is by using the `<style> `element, which is placed in the `<head>` section of your HTML document. This method is most commonly used when you want to include a small amount of CSS code in line with your HTML code. I don’t recommend this method as this is effectively mixing content with design. I have written a detailed article on the 6 reasons you shouldn’t style inline in your HTML  that you can read if you are interested in understanding why this is not recommended in more detail

The third way to connect CSS to HTML is by using the `<script>` element, which is placed in the <head> or <body> section of your HTML document. This method is most commonly used when you want to include a CSS file as a JavaScript resource.

Each of these methods has its advantages and disadvantages, so you’ll need to decide which one is best for your project.

As mentioned above, I recommend the first method for beginners who are learning how to connect CSS to HTML files.

Let us dive into the more technical elements and go through some code examples on how to connect a CSS stylesheet to HTML.

## **How to connect CSS to HTML**

Learn **[how to connect your CSS in your HTML file](https://worldofdev.info/how-to-connect-css-to-html-file/)** with a code example by **[Clicking Here](https://worldofdev.info/how-to-connect-css-to-html-file/)**