Creating a Windows Gadget


In this article, I have described the steps to create a Windows Gadget. I have demonstrated the article with an example of a digital clock gadget.
Gadgets are small applications which are hosted on the Windows Sidebar. Windows Gadgets are simply made up of HTML and JavaScript code. User-created gadgets are stored in the following folder:

C:\Users\<current user>\AppData\Local\Microsoft\Windows Sidebar\Gadgets

Every gadget is stored in its own folder under the above mentioned folder. The folder name should be the same as the gadget name followed by the  .gadget extension. Every gadget has two files associated with it. One is an HTML file with embedded JavaScript code to provide the functionality of the gadget. The other file is an XML file called gadget.xml and is also known as the gadget manifest.

Example Code

In the HTML file, the style element is used to specify the layout and format of the gadget. The script element is used to specify the content and working of the gadget. Finally a span element is used to display the gadget.

Following is the HTML/JavaScript code for our digital clock gadget (DigitalClock.html)



    <title>Digital Clock</title>




            margin: 0;

            width: 130px;

            height: 65px;




            width: 130px;

            top: 24px;

            text-align: center;

            position: absolute;

            font-family: Verdana;

            font-size: 10pt;



    <script language="javascript">

        function showtime()


            var now=new Date();       // Find current date

            var h=now.getHours();  // Find current hour

            var m=now.getMinutes();    // Find current minute

            var s=now.getSeconds();    // Find current second

            h=(h<10)?"0"+h:h;       // Convert hour to 2 digits

            m=(m<10)?"0"+m:m;       // Convert minute to 2 digits

            s=(s<10)?"0"+s:s;       // Convert second to 2 digits

            gadgetContent.innerHTML="<h2><font color='red'>"+h+":</font>

        <font color='lime'>"+m+":</font><font color='cyan'>"+s+"</font></h2>";

                    // Set time on the span element

            setTimeout("showtime()",1000); // Display time after every one second




<body onload="showtime()" bgcolor="black">

    <span id="gadgetContent"></span>



The gadget manifest file is an XML file which describes the properties of the gadget.

Following is the code of the gadget.xml file:

<?xml version="1.0" encoding="utf-8" ?>





  <author name="Azim">

    <info url="" />



  <description>Digital Clock</description>


    <host name="sidebar">

      <base type="HTML" apiVersion="1.0.0" src="DigitalClock.html" />

      <platform minPlatformVersion="1.0" />





Perform the following steps to add the gadget to the sidebar.

  • Create a folder called DigitalClock. gadget in the following folder:

C:\Users\<current user>\AppData\Local\Microsoft\Windows Sidebar\Gadgets

  • Copy the files DigitalClock.html and gadget.xml into the DigitalClock.gadget folder.
  • Right click on the sidebar and select Add Gadgets option.
  • Select the DigitalClockgadget.

Note: I have attached the DigitalClock.html and gadget.xml files along with this project.

The following figures show how to add the gadget to the sidebar.