Home  >  Article  >  Web Front-end  >  Why should css be placed in the head?

Why should css be placed in the head?

王林
王林Original
2020-11-16 10:53:442817browse

The reason why css is placed in the head: This will load the css style first. When rendering the dom, you already know your own style, so the rendering can be successful once. This method can prevent flickering, white screen or confusing layout.

Why should css be placed in the head?

Analysis:

This will load the css style first. When rendering the dom, you already know your own style, so you can render it once It will be successful, which can prevent flickering, white screen or confusing layout.

(Learning video sharing: css video tutorial)

If the css is placed at the bottom, then the dom needs to be rendered first, and then the previous dom will be re-rendered after loading the css. This requires two renderings and the user experience is poor.

In order to provide a better user experience, the browser's rendering engine will try to display content on the screen as soon as possible. It will not wait until all HTMl elements are parsed before building and laying out the DOM tree, so part of the content will be parsed. and display. In other words, the browser can render incomplete DOM trees and CSSOM, reducing the time of white screen as quickly as possible.

Related recommendations: CSS tutorial

The above is the detailed content of Why should css be placed in the head?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn