Implement Lightbox using jQuery plugin

Hi guys!

Lightbox is a well-known JavaScript technique used to display images or any web content using modal dialogs. Not too long ago, the lightbox plugin was written in jQuery that allowed developers to modify the code and come up with new plugins that carry out the same task.

Colorbox is one such jQuery plugin that we can use to implement a lightbox. Through this post, I will try to implement a sample HTML page that displays a lightbox using the Colorbox plugin.


<!DOCTYPE html>
<html lang="en">
    <meta name="generator"
    content="HTML Tidy for HTML5 (experimental) for Windows" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="" />
    <meta name="author" content="" />
    <title>LightBox Demo</title>
    <link href="" rel="stylesheet" />
    <link href="" rel="stylesheet" />
    <script src=""></script>
    <script src=""></script>
    <script src=""></script>
    <div class="container">
      <a href="#ShowLightBox" class="colorbox-element">Show LightBox</a>
    <br />
    <div style="display:none">
      <div id="ShowLightBox" style="margin:0 auto;padding:10px; background:#fff;">
        <!--sample form -->
        <div class="panel panel-info">
          <div class="panel-heading">
            <div class="row">
              <div class="col-md-10">
                <h3 class="panel-title">My Form</h3>
        <div class="form-group">
        <input type="text" placeholder="Name of the customer" class="form-control" /></div>
        <div class="form-group">
        <input type="text" placeholder="Phone of the customer" class="form-control" /></div>
        <a href="#" class="btn btn-default">Submit</a>
      $(document).ready(function($) {
            $(".colorbox-element").colorbox({inline:true, width:"70%", height:"95%"});

Save and open the above web page in any browser and you should see the following output!