Make Any App Load Faster With Just 6 Lines of HTML
A six-line fade-in that hides the half-rendered page until it’s ready, why it changes how fast an app feels, and how to check it in DevTools and Lighthouse.
Improving performance often sounds like it needs complex caching layers, micro-optimizations or a total architecture redesign. But there is a simple approach that can make almost any web app feel instantly faster. It takes only six lines of HTML.
The six lines set the page body's opacity to 0 with a 0.3 second transition, then set it back to 1 in window.onload. The half-rendered page, layout shifts and late fonts stay hidden until everything has loaded, and the finished UI fades in. Actual load time stays about the same; the app only feels faster.
Engineering teams use this technique to reduce perceived load time, improve first contentful paint and deliver a smoother user experience without touching backend logic.
In this article you will learn why it works, how to implement it, and how to validate its impact.
Why Does Perceived Speed Matter More Than Actual Speed?#
Perceived speed matters more because users judge an app by how soon something appears on screen, not by when every asset has finished loading.

Users do not wait for “the app to load”. They wait for something to appear. If the screen stays blank, even 1 second feels slow. If the screen shows meaningful UI or skeletons within 150 ms, the brain reads the app as fast.
This is why modern frameworks ship splash screens, skeletons and instant-feedback patterns. But you can get the same effect with nothing more than native HTML.
The 6 Lines That Change Everything#
The six lines are a CSS rule that makes the page body invisible and a script that makes it visible again when the window finishes loading.
Here is the exact snippet:
These six lines do something very simple yet powerful.
They hide the unstyled, half-rendered app until everything is ready, then fade in the fully loaded UI.
This removes the classic problems of:
- Flash of unstyled content
- Blocky layout shifts
- Components rendering half-finished
- Delayed font loads
- Perceived lag during hydration in React, Vue or Next.js apps
The user sees a clean, smooth transition instead of a chaotic load sequence.
How Does the Fade-In Snippet Work?#
The fade-in snippet lets the browser render the page at zero opacity, then sets opacity to 1 in window.onload, so the CSS transition fades in the finished page.

Let’s break the snippet down.
1. Set the initial body opacity to zero#
The app renders fully behind the scenes but is not visible yet.
2. Fade in on window load#
This waits until all assets have loaded, then smoothly reveals the page.
The brain reads this as a fast app because nothing visibly “breaks” during the initial paint.
Real Example: Fixing a Slow React Single Page Application#
In a React single page application, the fix is to add the fade snippet to index.html or public/index.html, so the white page, popping header and shifting components stay hidden until the app has loaded.
Here is a common problem.
You open a React app and the first thing you see is:
- an empty white page
- then the header pops in
- then fonts load
- then components shift
- then styles apply
By the time the app settles, users already feel it’s slow.
Add the fade snippet to your index.html or public/index.html file:
Refresh the app and it feels instantly polished.
The same logic applies to any stack: React, Vue, Svelte, Angular, Next.js, Remix, plain HTML or legacy PHP sites.
Why This Trick Works Even Better on Heavy Apps#
The fade trick helps heavy apps more because their bundles, hydration, network calls and separately loaded CSS cause more flashes of incomplete UI to hide.
Large applications often have:
- heavy bundles
- runtime hydration
- multiple network calls
- third-party libraries
- analytics trackers
- CSS frameworks loading separately
All of these cause flashes of incomplete UI.
Hiding the app until it is visually stable cuts user frustration significantly.
This technique does not reduce actual load time. It reduces felt load time, which matters more in real usability studies.
Adding a Custom Loading Screen (Optional but Effective)#
A custom loading screen shows a #loader element while the body is hidden, and the same window.onload handler hides the loader and fades the page in.
To go one step further, replace the blank background with a loading screen:

This gives users instant feedback while the real app loads invisibly behind it.
Performance Impact You Can Validate#
You can check the fade-in's effect with the Chrome DevTools Performance panel, Lighthouse audits and user testing.
You can measure the improvement with:
- Chrome DevTools Performance panel: check the “First Contentful Paint” visual timeline.

- Lighthouse audits: perceived performance improves even though actual time stays about the same.

- User testing: most users describe the app as “faster” or “more responsive”.
Does Hiding the Page With Opacity Hurt SEO?#
The opacity fade-in is safe for SEO because the content still loads normally in the HTML; only its visibility changes.
This technique is safe for SEO because:
- content still loads normally in the HTML
- search engines don’t care about the opacity
- screen readers read the content regardless of visibility
Just avoid long fade durations. Stick to 0.2 to 0.4 seconds for the best UX.
A Quick Before and After#
Before: The app flashes white, styles pop in, components shift and fonts snap into place.
After: The app appears clean, stable and fully rendered.
This one tiny improvement often makes a platform look like it has professional-level performance engineering behind it.
Frequently asked questions#
Does a fade-in make a web page load faster?
No. A fade-in does not reduce actual load time. It hides the half-rendered page until everything has loaded, which makes the load feel faster.
How long should a page fade-in transition be?
Keep the fade between 0.2 and 0.4 seconds and avoid long durations. The snippet in this post uses 0.3 seconds.
How do I stop the flash of unstyled content in a React app?
Add the fade snippet to index.html or public/index.html. The body stays at opacity 0 until window.onload fires, then fades in with styles, fonts and layout already in place.
Do screen readers still read a page hidden with opacity 0?
Yes. The content still loads normally in the HTML, and screen readers read it regardless of its visibility.
Conclusion#
Optimizing performance does not always require complicated tools. With just six lines of HTML you can deliver noticeable perceived-performance gains, reduce visual jank and create a smoother experience for every user.
Try it on your project today. The difference is immediate.
Written by Dhananjay Aggarwal

