Javatpoint Logo
Javatpoint Logo

How to Add External CSS in HTML

In this article, we will discuss how to add external CSS in HTML.

HTML

HTML is short for Hypertext Markup Language, which is utilized to give the structure of the web page.

CSS

CSS is the short for Cascading Style Sheet which is utilized to give the style to the elements of HTML so that they look attractive to make the web page look eye-catching.

There are 3 methods by which we can add CSS in HTML:

  1. External CSS
  2. Internal CSS
  3. Inline CSS

We will comprehend each method properly one by one.

1. External CSS

External CSS is utilized to give the style on multiple HTML pages because we use a separate file that contains CSS. This separate file is saved with the .css extension. This file can be added to any HTML document. If there are changes in the style, then we can easily change the style without even changing the HTML document.

We can link the CSS file with the HTML document to provide the style of the web page. We can use the "link" HTML element to add the external file. The <link> tag comes under the <head> tag. There are many attributes that <link> tag involves, such as src, rel, type, etc. The "src" attribute is used to define the location, so the CSS file name that we want to add is written inside it.

The "rel" attribute is used to explain the relationship between the CSS document and the HTML document. The "type" attribute is utilized to define the content we are linking with the HTML document. The "type" attribute is optional, but if utilizing it, then for the stylesheet, we have to set the value as text/CSS.

Demonstration to Add External CSS in HTML

We will construct separate files of HTML & CSS and then link both files using <link> tag.

CSS code:

HTML code:

Output:

When a CSS document is not linked to an HTML document, then the web page will appear, as you can witness below. It is very simple and needs to look more eye-catching.

How to Add External CSS in HTML

When a CSS document is linked to an HTML document, the web page will appear, as we can witness downward. It is modern and looks eye-catching.

How to Add External CSS in HTML

2. Internal CSS

Internal CSS is written inside the "style" HTML element. The CSS that we need to apply to the HTML document is written inside the <style> tag, and the <style> tag is written inside the <head> tag after the <title> tag.

Demonstration to add internal CSS in HTML:

We will write both CSS and HTML in the same document in this illustration.

Code:

Output:

Here is the output downwards, in which we can witness the login form, which is given a style using internal CSS.

How to Add External CSS in HTML

3. Inline CSS

When CSS is written inside each element where we require to apply style then it is known as inline CSS. The "style" attribute is utilized to add the style. It is not recommended to use because it takes a lot of time to apply style to each HTML element and it is hard to alter the style of any element afterwards.

Demonstration to add inline CSS in HTML:

We will construct a list box and add inline CSS in this illustration.

Code:

Output:

Here in the output, we can witness a list box, which is given style utilizing inline CSS.

How to Add External CSS in HTML

Conclusion

We have comprehended how to add external CSS in HTML. Some points to remember are given below:

1. There are three methods to add CSS in HTML:

  • External CSS: It is written in a separate document with the .css extension.
  • Internal CSS: It is written inside <style> tag under <head> tag.
  • Inline CSS: It is written inside each element that we require to style using the "style" attribute.

Next TopicHTML Extension





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA




news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news
news