<!DOCTYPE html>
<html lang="en-US">
<head>
<style>
div{
display: inline-block;
text-align: center;
width: 22px;
}
</style>
</head>
<body>
<script>
var i, k = 1, m = 1;
for(i=1; i<=5; i++)
{
m = k + i - 1;
for(j=1; j<=i; j++)
{
if(i%2 == 1)
document.write("<div>"+ k +"</div>");
else
document.write("<div>"+ m-- +"</div>");
k++;
}
document.write("<br>");
}
</script>
<p><strong>Note</strong>: In this example, the structure of the pattern is more important. So little <a href="/css" target="_blank">CSS</a> is added.</p>
</body>
</html>