Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the three methods of applying CSS in HTML?

Shulou Source: shulou.com Published: 2022-06-03 06:27:40 09月23日 Update

This article is to share with you what are the three methods of applying CSS in HTML. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Do you understand the method of applying CSS to HTML? here to share with you, there are mainly inline, internal and external three ways to apply CSS to Html, the internal style serves the entire current page, the external style serves multiple pages of the entire site, and the inline style goes directly into the HTML through the style attribute. I believe that the introduction of this article will give you a harvest.

Three methods of applying CSS in HTML

There are three ways to apply CSS to HTML.

Inline

Inline styles are nested directly into HTML through the style attribute.

It looks like this:

Sample code

Text

This will be the specified paragraph turns red.

Our suggestion is that HTML should be independent, style-free documents, so inline styles should be avoided in any case.

Inside

The internal style serves the entire current page. In the header tag head, the style tag style contains all the styles of the current page.

It looks like this:

Sample code

CSSExample p {color:red;} a {color:blue;}

This will make all paragraphs of the page red and all links blue. The inline style is similar, you should separate HTML documents from CSS documents.

External

External styles serve multiple pages of the entire site. This is a separate CSS document, and a simple example is as follows:

Sample code

P {color:red;} a {color:blue;}

If the document is saved as "web.css", it can be connected to the HTML document like this:

Sample code

CSSExample

Save the HTML document, now that HTML and CSS are connected, you can use the css tags you defined in the css file in your html.

These are the three methods of applying CSS in HTML. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Styles documents applications pages methods code examples services tags multiple attributes more paragraphs knowledge articles red websites approaches independent practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information Shulou Tech Info Apple Microsoft