Skip to main content

Why does a horizontally-centered element with margins flicker or jump on page load?

Adding margin to a horizontally-centered element causes it to briefly render with incorrect styling before snapping to the correct position, creating a visible flicker on page load.

Written by Sofia Maconi

Adding margin to an element with its horizontal alignment set to "centered" causes the element to briefly render with incorrect styling before immediately re-rendering correctly. This creates a visible flicker or jump when the page loads.

What you might notice

  • A centered element with margins briefly appears in the wrong position on page load

  • The element "jumps" or flickers into its correct position a fraction of a second after load

  • Removing either the margin or the centered alignment stops the behaviour

Workaround

Apply padding to the parent element instead of margins on the element itself. This achieves the same visual spacing without triggering the re-render.

Did this answer your question?