Theming: “style it as if there is no JavaScript!”

In order to enhance user experience, almost all modern web sites use JavaScript these days. Displaying dynamic forms and other elements using jQuery or some other JavaScript library is quite common. Not only that, those libraries have been regarded standard for web for many years.

As a developer I use different JavaScript/jQuery scripts on my projects. They are usually closely connected with theming (HTML and CSS). Most of those scripts have well-arranged and divided styles and JavaScript code. However, we can bump into many of those who don't have it or it is even us who made troubles with inadequately combining JavaScript and CSS code.  

Therefore, “style it as if there is no JS!”.

These kind of troubles are most noticeable, when there is a lot of JavaScript code running in the background. As a result server spends some time to run the whole JS code, what then causes the web-site »flickering«.


To illustrate what's been said, I am going to show you an example:

<html lang="en">
  <meta charset="UTF-8">
  <link href="style.css" rel="stylesheet">

  <!-- content -->
  <div class="container">
    <nav class="menu">
        <li><a href="#">Menu item 1</a></li>
        <li><a href="#">Menu item 2</a></li>
        <li><a href="#">Menu item 3</a></li>
        <li><a href="#">Menu item 4</a></li>
        <li><a href="#">Menu item 5</a></li>
    <h1>This is demo page</h1>
    <div class="content">
      <p><a href="#" class="show-menu">Open menu</a></p>
      <p>content </p>

<script src=""></script>
<script src="scripts.js"></script>



If we want to hide the menu navigation, because we are going to call it with JavaScript/jQuery code using click event, it's most convenient to apply it directly in CSS, not using JS.

An example of an incorrect use:

  $('').on('click', function (){

Let's look at the GIF animation depicting how the navigation appears and finally disappears:

Demo page gif

A correct use:


.menu { display:none; }


  $('').on('click', function (){

The menu element was hidden already in the first phase using CSS, which loads immediately after visiting the website. Afterwards we load the rest logic of JS, which will display our menu.

With such correct use the menu will be hidden, even when JavaScript won’t be (up)loaded. This will enable the website to load correctly and avoid “flickering”.

How to test a website to find out if it is loading correctly?

The best way to do this is to entirely disable JavaScript support in the browser and once more click through the whole website.

I would recommend using Firefox web browser together with an Add-on “Web Developer”.

First enable Add-on, then go through following steps to disable JavaScript code:

1. Disable

2. Disable JavaScript

3. Disable All JavaScript


Now you have to examine your website to find out if there are any elements, which are not supposed to show up or they are displayed incorrectly. Adjust your JS and CSS code in order to get correct display. After enabling JavaScript, website should be displayed correctly.

Many developers are making these mistakes unconsciously, as they are not immediately visible and because the website does load. Those mistakes are easily seen by users with slower internet connections, or even when we use bigger amount of JavaScript code on the website, which could slow down the whole loading of the website and accordingly showing up all mistakes.

Therefore, “style it as if there is no JS!”.