Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How do I introduce CSS in HTML? How many ways?


May 29, 2021 Article blog


Table of contents


Once we've written web pages in HTML, we need to optimize some styles with CSS to beautify the pages and enhance the experience. S o how do you introduce CSS in HTML? H ow many methods are introduced? This article answers for you.

In-line introduction

Add the CSS style directly to the label. I f using this method is too cumbersome and does not reflect the CSS style. Therefore, this method is less used.

<p style="color:red">行内引入CSS样式</p>

Embedding is introduced

The styles involved in the page are centrally written between <head></head> all CSS styles are labeled for this page, there are no extra commands, and the page loads faster by reading the style directly in the HTML document. However, the shortcomings of this method also exist, not convenient to modify, too much code, follow-up troubleshooting needs to spend more thought, not good maintenance.

<style type=”text/css”>

pcolor:red }

</style>

Import file references

<!-- 导入外部样式:在内部样式表的<style></style>标记之间导入一个外部样式表,导入时用@import。 -->  
<style type="text/css">  
 @import "jisuan.css";  
</style>

Link import

Link imports are similar to imports, introducing CSS from the outside. L ink import works a little better when client users browse the site. Currently commonly used import methods are also linked import, this way is also the most reflective of CSS characteristics of the way, but also convenient for future maintenance.

<link href="文件地址" rel=”stylesheet” type=”text/css” />

Here are all the answers to how to introduce CSS in HTML and how many methods to do so.