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.
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!