Saturday, 30 June 2018

Make a beautiful Light-box for images in HTML5, CSS and JavaScript

Most of the users get irritated when the click on a photo to view bigger on a website and land straight on the image URL. Then, to read existing post, they have to click the previous button to come back.

For the solution, of course, should use a Light-box and Today-we're looking into that. Let's start to make a beautiful Light-box in HTML5, CSS and JavaScript!


Assuming that when the user will click on the image, and the light box will open, we just have to set an on-click event to a small image thumbnail. The simple HTML markup is crated below.

<img src='image.png' onclick="document.getElementById('box').style.display='block';

Where, we have a image and for light box and background, below is the markup.

<div id="box" class="box">
    <a href='#' onclick="document.getElementById('box').style.display='none';
    <img id='pic' src=''>
<div id="bg" class="bg"></div>

After this, we will stylize it little using CSS.
.bg {
  display: none;
  position: absolute;
  top: 0%;
  left: 0%;
  width: 100%;
  height: 100%;
  background-color: black;
  z-index: 1001;
  -moz-opacity: 0.8;
  opacity: .80;
  filter: alpha(opacity=80);
.box {
  display: none;
  position: absolute;
  top: 25%;
  left: 25%;
  width: 50%;
  height: 50%;
  padding: 3px;
  border: 8px solid #435;
  z-index: 1002;
  overflow: auto;
    font-size: 20px;
    text-decoration: wavy;

As we have already embedded the JavaScript in markup above, when user will click on any image, link or element, the light box will popup.It will show the same image as we have clicked because of document.getElementById('pic').src=this.src.

But the problem you will see is that the image remain at the original size of its URL.So we can fix it by CSS.
  width: 500px;

This is a very simple and lightweight light-box for one or two pictures only.Fore more than that, or many, you can't manually set the functions in its on-click attribute.
There we will need some more shortcut.You can start with writing the script for that as CSS-magz will make that as well and post soon.To get updates, do like our Facebook page.

Click on image below to see it in light-box.


see the better version here.

Saturday, 23 June 2018

How to Make popup for liking Facebook page on Blogger using Sweet Alert2?

So we want something that pops up when the user is about to leave or to enter the email when subscription box opens on our blog? So we are making that with a Javascript framework called Sweet Alert. Sweet Alert is a better way to display output to the user rather than to use the usual JavaScript alert();.
How to Make popup for liking Facebook page on Blogger using Sweet Alert2?

So for that, first we need to add the SweetAlert's JavaScript file into our document. So we use their CDN to get the file. Add the below script into the head section of the document.

<script src=""></script>

Now, its time to get in our HTML. For example, if you want to make the Facebook page linking handle to be popped up, go to Facebook Developer's social plugin, and then paste the URL of your Facebook page and click on get the code. If you prefer the iframe, the code will look something like below(Excluding page URL).

<iframe src="" width="1200" height="70" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe>

Copy the code. Now its time to set up the alert!

Applying the SweetAlert

Now, add the following code on your main page.
  title: "<i>Like Or Facebook Page!</i>", 
  html: '',  
  confirmButtonText: "Liked!", 
You can modify this by changing the heading and button text.
Now we will add the above Facebook iframe script.You can also add some other stuff like twitter follow etc.So the final script will look something like this.
  title: "<i>Like Or Facebook Page!</i>", 
  html: '<iframe src="" width="inherit" height="inherit" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true" allow="encrypted-media"></iframe>',  
  confirmButtonText: "Liked!", 

But you may face a problem with this and that is that facebook's iframe takes a ittle time more to load.For that we can use a preload in HTML.So we are going to use it like below.
<link rel="preload" href="" as="document"">

So with that you can add simple alert box to your blog or website!Do experiment with it and with that, don't forget to like our Facebook page.

Have a Look at Demo once!

Wednesday, 13 June 2018

Change cursor styles using CSS

Well we sometime bore using the same same and same cursor or the theme of cursors on every website.Want to try some or make some new sets of cursor for your website or blog? Here's how to do it using CSS.

So we start From CSS. CSS has cursor property in which you can specify the cursor styles.At the date of writing this post, cursor has 36 types of cursors you can use.They can be further extended by using our own cursors in image files or .cur(cursor file type).


Syntax for cursor

You can apply the above cursors to your body tag or any particular HTML element.The syntax vaild in all the browsers is given below.
    cursor: value;
In the value field, all the cursors you tried by hovering above can be applied.For example,
The cursor is supported in all the desktop browsers(of-course, they will not come in mobile or touch screens).cursor: none; is not supported until Firefox 3, Safari 5, and Chrome 5 and not at all supported in Internet Explorer or Opera.not-allowed, no-drop, vertical-text, all-scroll, col-resize, row-resize are not supported in Internet Explorer and Opera.
For more browser compatibility info, visit Mozilla.
Inherit and initial are also supported in cursor's value field.

Cursor using URL

You can define or design your own cursor for your website like below or download form websites which provides free cursors.
cursors with different styles
Now the question is- How to implement custom cursors to the websites?
For that you need to use css cursor property.
  cursor: url(images/cursor.png), auto;
where you need to add the image cursor file URL or .cur file, and auto is fallback here.Any other can also be used depending on situation.Image URL cursors not at all supported in Opera till now.

To apply to the whole HTML page, use this in body instead-
  cursor: url(images/cursor.png), auto;

Live Demo

This can be very useful especially in web apps of a special theme-sort.Thanks for reading do follow CSS-Magz.

Saturday, 9 June 2018

Make A Calculator In JavaScript

Making a calculator in JavaScript is not have been taught so far.As it supports mathematical calculations.Now, we will make a simple calculator using HTML5, CSS and JavaScript.

For making it,  as always we need a markup.We will make a div element and inside that, a display and buttons.Our structure will be as below.



<div class='calc'>
<div id='disp'>
<button id='1'>1</button>
<button id='2'>2</button>
<button id='3'>3</button>
<button id='add'>+</button>
<button id='4'>4</button>
<button id='5'>5</button>
<button id='6'>6</button>
<button id='subtr'>-</button>
<button id='7'>7</button>
<button id='8'>8</button>
<button id='9'>9</button>
<button id='mult'>x</button>
<button id='clear'>CE</button>
<button id='0'>0</button>
<button id='dec'>.</button>
<button id='division'>/</button>
<button id='ans'>=</button>
Okay, so we have made the main division 'calc' and then added another <div> for display and then added buttons for all the numbers and functions.

CSS for calculator

.calc button{
  margin:5px 5px 5px 15px;
And for display, we are going to add the properties.You can add that 7 segment led display font too, will look realistic!
And here comes our main function- JavaScript.

var disp = document.getElementById("disp");
function ud(n){ 
disp.innerHTML += n ;
function ans(){
function clc(){

document.getElementById("1").addEventListener("click",function(){ ud(1); });
document.getElementById("2").addEventListener("click",function(){ ud(2); });
document.getElementById("3").addEventListener("click",function(){ ud(3); });
document.getElementById("4").addEventListener("click",function(){ ud(4); });
document.getElementById("5").addEventListener("click",function(){ ud(5); });
document.getElementById("6").addEventListener("click",function(){ ud(6); });
document.getElementById("7").addEventListener("click",function(){ ud(7); });
document.getElementById("8").addEventListener("click",function(){ ud(8); });
document.getElementById("9").addEventListener("click",function(){ ud(9); });
document.getElementById("0").addEventListener("click",function(){ ud(0); });
document.getElementById("dec").addEventListener("click",function(){ ud('.'); });

document.getElementById("add").addEventListener("click",function(){ ud('+'); });
document.getElementById("subtr").addEventListener("click",function(){ ud('-'); });
document.getElementById("mult").addEventListener("click",function(){ ud('*'); });
document.getElementById("division").addEventListener("click",function(){ ud('/'); });

document.getElementById("clear").addEventListener("click",function(){clc(); });
document.getElementById("ans").addEventListener("click",function(){ ans(); });
First we add all the buttons event listener click.Than we add function ud() to update user display and ans() to eval the mathematical expression and to show the answer.
Function clc() is to clear the display.

Live Demo

Below you can see the live demo of the calculator.You can try using it.Although this was very simple calculator.Before leaving, do remaimber to follow and like our Facebook page.

Friday, 8 June 2018

How to detect if the user is in Incognito mode using Javascript?

How to detect if the user is in Incognito mode using Javascript?
Sometime before, we had talked about the incognito mode in Google chrome browser. Today, we are going to see how we can detect it using simple lightweight Javascript.

Before moving further, let we see what happens in Incognito mode or how incognito mode is different from normal browses?
Incognito mode or private browsing is the same normal browser but with deducted and controlled functions. Functions like saving history and cookies are disabled. through the websites can store cookies, they are deleted once the browser or incognito session closed.

Google, on its help page says that in Incognito mode-

  1. Chrome wont save our history.
  2. Downloaded files and bookmarks will b kept.
  3. Your activity isn't hidden from ISP or school or college employee.
But still, we can find that user is in Incognito mode or not.

How to Detect if the user is in Incognito mode?

For that, From a answer on stackoverflow, I came to know that window.RequestFileSystem function returns in error.So by using try catch, we can find if the user is in incognito mode.
var fs = window.RequestFileSystem || window.webkitRequestFileSystem;

fs(window.TEMPORARY, 100, function(fs) {}, function(e) {

    alert("You are in Incognito Mode.")
So this way you can detect in Google chrome if the user is in incognito mode.

Live Demo

Everything Seems Fine

What others are saying

Since you can detect that user is in incognito mod or not, many says that this is the threat to their privacy and anonymity.Since Google chrome and other browsers may define temporary storage in feature that will clear immediately after the session closes. Then it will be more difficult for us to detect the incognito mode.

Add this one line code(after minifying) in your HTML's <head> section and in place of JavaScript alert, us your own function.

Sunday, 3 June 2018

Image SEO : The important things you should know

Images are the most important component of the blog or the piece of content that you are writing.Without images, the post looks like a tree without leaves.

Images worth a thousand words.So bloggers always add images to their blog post to make it more enlighten and attractive.This is  a very good thing but the most people fails here - in Image SEO.

Image SEO is the most important thing we will discuss today as you can gain lot of traffic right from the 'image' section of any search engine.People are searching for images and now a days Google had removed direct download button, forcing users to go on their sites.So, from here only, we can get the traffic.

So lets have a look at the important things we need to know about Image SEO.
Image optimization for SEO.

Add the Images from right source

Most of the Bloggers still searching on Google for images and directly add them in their blog posts.This is completely wrong and you may have to go through some legal disputes for that.As the images shown by Google are subjected to copyright, the owner has full right over his images.
Image may subject to copyright in
So the question arrives-So from where we should gather the images?Shall we have to make or click our own?
And the answer is yes!You can of course click the images.but someone living on mars cannot click the image of Eiffel tower in Paris as he have to come there.
That's why we have the stock websites.

Stock websites are the websites which stores the images, vectors, illustrations and video footage which user uploads from the different part around globe.Then anyone can download it by paying some royalty fee.That's how the stock photography works.But everyone can't afford to buy these images from these sites.So we have the free image stock websites.

Free stock image websites like Pixabay, provides free images to users and can be downloaded without paying a single penny.There are many more stock image websites from which you can download the images such as-

  2. Pexels
  3. Unsplash
  4. Shotstash
  5. SuperFamous
It is very safe to use any of the image from the above site.You are free to mention more sites in comment box below of you know any.

The another way to grab images from Google or Bing search engine is that filter it.Filter the images based on their license.

In Google Images, click on 'tools' button.Some options will pan down. Click on 'Usage Rights'.Chose the option labeled with modification or labeled for reuse.
google images usage rights.
As shown in the above image, you can use the images labeled for reuse by directly copying from Google.
In Bing, Go in Images tab, click on 'Filter' button on extreme right.Again, as Google, some options will come down.Select License.Chose any one of the options marked red in below image.
But as experienced, not very good and on to point images are not found.But still you can use this as an method for getting images.

Compress the images

Images takes lot of time to download.Sometimes, more than 70% of page load time is used for getting images.This is all because the size of image is huge as compared to main html or CSS and JavaScript files.
images take more time to load

So, you need to compress the images.Compressing images not only saves space, but also makes the page to load fast.
Some of the online image compressors are given below.

  1. CompressorJPEG
  2. CompressImage
  3. Image Compressor
These are some tools which will help you to compress down your images.there are many such image compressors online.Some of them supports bulk images compression, while some not.

this is very irritating work of compressing images, then adding.There is no shortcut for it?Yes!There is! If you are using WordPress, then you can use plugin for it.There are many plugins which will compress images for you!

But if you are using Google Blogger, you don't have to worry even a single bit.It is because after uploading image, it directly compress it into small, medium, large and Extra Large.And still you can use original image if you want.
Image Compression.
options available in Google Blogger for different image sizes.
There is no very much advantage using ful quality image on web.Consider, if you used 1080x540px image,it may load 200x100 or 500x250px on mobile phones.So we are just slowing down our website in unnecessary images.

Using ALT text

Alt tag is one of the most important text.Many bloggers make mistake here.They do not at all use these texts.
These text get used for two reasons. First is is anyone using their browser in 'text-only' mode, then he cannot see the images but he can know the place of the image.In that place  you might have notice some time, that a text is shown.This text is alt text.In second case, if the image on the server got deleted, it returns with 404 error.Then , in that image a text is is shown and that is alt tell that you input here.
alt text for images

In both the cases, the main purpose is to get the idea of what the image is to the user if he or she is unable to view the image.

What is Alt text?Alt means alternate text.It is a simple and short text for an image that describes the whole image.So, remember to use alt from now on wards, if you weren't.

Use the right keywords while naming the images

The right keywords always do well in Image SEO. So, you need to use the right keywords while naming the image.
You can name the image like below.For example-
Rather than-
If you want to find right keywords, go on NeilPatel's website and do a keyword research.

So that's were the tips about image SEO which can rank images from your bog so high that you can get more traffic through images rather than web search.

Friday, 1 June 2018

How to make a CSS framework

We always need simplicity in working with CSS and JavaScript and that's why the developers out there made different frameworks and libraries and API's depending on their needs. CSS and JavaScript frameworks makes its easier and saves lot of time writing the same lines again and again and do a task in few lines of code.

Today, we are going to create a simple library which of course, you can extend based on your needs.There is no strong need at the time of writing this, as there are already lots of  libraries available on web.Any one of them can be super-handy to be pick out.But still, we are going to make one as we can stylize t as per our needs and you can use it on your whole website or blog.

Making a CSS library is not a great thing as compared to making a JavaScript library.Since the simple steps are-

  1. Define your own classes in a CSS file.
  2. Use your own starting name to avoid misconception with other libraries.
  3. Minify the library and import it into a document.
With this, we can  make a simple CSS3 framework.

Making a CSS file

Lets call our framework 'Cmagz'.So the file name Cmagz.css is made.

First we will add the simple properties to html, body,*(all) , * before and after etc.
    box-sizing: border-box;
    -ms-text-size-adjust: 100%;
    -webkit-text-size-adjust: 100%;
    font-family: Verdana, sans-serif;
    font-size: 10px;
    overflow-x: hidden;
*:after {
    box-sizing: inherit;
So what done is above is we have sized the html in border-box so we can add height and width.To make a ll field compatible, we have hidden the x- scroll bar.

Now we are going to select the element and make them display as block because some or most of the browsers shows them not as block.For example, section.

summary {
    display: block;

video {
    display: inline-block;

progress {
    vertical-align: baseline;
So now we gonna starting with some of the tags and their default values.For example, if you want to add border to <img> tag, then you can add it here below.

a {
    background-color: transparent;
    -webkit-text-decoration-skip: objects;

a:hover {
    outline-width: 0;

figure {
    margin: 1em 40px;

img {
    border-style: none;

svg:not(:root) {
    overflow: hidden;

samp {
    font-family: monospace, monospace;
    font-size: 1em;

hr {
    box-sizing: content-box;
    height: 0;
    overflow: visible;

textarea {
    font: inherit;
    margin: 0;

optgroup {
    font-weight: bold;

input {
    overflow: visible;

select {
    text-transform: none;

html [type=button],
[type=submit] {
    -webkit-appearance: button;

[type=submit]::-moz-focus-inner {
    border-style: none;
    padding: 0;

[type=submit]:-moz-focusring {
    outline: 1px dotted ButtonText;

fieldset {
    border: 1px solid #c0c0c0;
    margin: 0 2px;
    padding: .35em .625em .75em;

legend {
    color: inherit;
    display: table;
    max-width: 100%;
    padding: 0;
    white-space: normal;

textarea {
    overflow: auto;

[type=radio] {
    padding: 0;

[type=number]::-webkit-outer-spin-button {
    height: auto;

[type=search] {
    -webkit-appearance: textfield;
    outline-offset: -2px;

[type=search]::-webkit-search-decoration {
    -webkit-appearance: none;

::-webkit-input-placeholder {
    color: inherit;
    opacity: 0.54;

::-webkit-file-upload-button {
    -webkit-appearance: button;
    font: inherit;
Stylize the h1-h6 tags.:
h1 {
    font-size: 38px;

h2 {
    font-size: 32px;

h3 {
    font-size: 26px;

h4 {
    font-size: 22px;

h5 {
    font-size: 20px;

h6 {
    font-size: 18px;
After that,
.cmagz-image {
    max-width: 100%;
    height: auto;
.cmagz-input {
    padding: 5px;
    display: block;
    border: none;
    width: 100%;
.cmagz-radio {
    width: 24px;
    height: 24px;
    position: relative;
    top: 6px;
Then there you can add some CSS animations.So for that, first we need to make @keyframes like below.
.cmagz-animation-fade {
    animation: fade 2s infinite;

@keyframes fade {
    0% {
        opacity: 0;
    50% {
        opacity: 1;
    100% {
        opacity: 0;
For making this framework more enlightening, we can add much more animations like fade, hide , show, pop-up , disappear, blink etc.Design your own div box, put all CSS code into a file and give a class name like cmagz-divbox.
There are many CSS frameworks available in the market, you can make your own or mix two of them to add same functionality into one!Minify the CSS file to save up the space and import it into document.
<link rel="stylesheet" href="">
Okay, so with that, you can design your own CSS3 framework like this.Any queries?Ask in comments.