search
HomeCommon ProblemWhat are css reflow and redraw

Reflow and redraw in CSS refer to the two stages that cause the browser to recalculate and render the page when the size, position, color and other attributes of the element change in the browser. Since both reflow and redraw require the browser to recalculate and render the page, they will bring performance losses. Therefore, when writing code, you should try to avoid frequent reflow and redraw.

What are css reflow and redraw

# Operating system for this tutorial: Windows 10 system, Dell G3 computer.

In the browser, when we change the size, position, color and other attributes of an element, it will cause the browser to recalculate and recalculate the page. rendering operations. Among them, these two stages are called CSS reflow (reflow) and repaint (repaint).

CSS reflow means that when the size, layout, or position of a DOM element changes, the browser needs to recalculate the geometric properties of the element and rebuild the rendering tree of the page. Reflow will definitely cause redraw, but redraw will not necessarily trigger reflow.

CSS redraw means that when the change of element style does not affect the layout, the browser only needs to redraw the element without recalculating the layout. For example, changing the color of an element will only cause a redraw and will not trigger reflow.

Since reflow and redrawing require the browser to recalculate and render the page, they will cause performance losses. Therefore, when writing code, you should try to avoid frequent reflow and redrawing. You can take the following optimization measures:

  1. Avoid frequent modification of DOM styles.
  2. Use transform to replace operations such as top/left that cause reflow.
  3. Use document fragment (DocumentFragment) to perform DOM operations, and finally add it to the document at once.
  4. Avoid using CSS expressions as they cause the browser to recalculate each time.
  5. Avoid frequently reading layout information or using attributes such as offset series, which will force the browser to reflow.

In short, writing code properly and reducing reflow and redraw operations can improve page performance and user experience.

The above is the detailed content of What are css reflow and redraw. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),