 <p>It's really difficult to guess what's the issue there without more complete example. One thing that could be the reason is empty cells which are collapsing. Also I've moved the innerHTML to html variable which is appended just once..</p> <p>to compensate that try this code which is adding a non breaking space to empty cells:</p> <pre><code>var Htmltable = document.getElementById('table'); var day = 1; var html = ''; for(i = 1; i &lt;= 6; i++){ //weeks in a month (rows) html += '&lt;tr&gt;'; for(j = 0; j &lt;= 6; j++){ //7 days in a week (coloumns) html += '&lt;td&gt;'; if(day &lt;= wca.totDayInMonth){ html += day; day++; } else { html += "&amp;nbsp;"; } html += '&lt;/td&gt;'; } //if day &gt; totDayMonth - stop making line html += '&lt;/tr&gt;'; } Htmltable.innerHTML += html; </code></pre>