A virtual teacher who reveals to you the great secrets of Base64

<input>

The <input> tag is one of the most common form elements. The main reason for its high popularity is that it allows you to create various field types, such as button, checkbox, password, file, time, email, hidden, and many others. One of these types is image, which transforms the <input> into an <img> and acts as a submit form button. When a form is submitted via such a button, the value of the <input> becomes the XY coordinates of the image that the user clicked on.

As well as <img>, the <input type="image" /> requires the src attribute. Typically, it contains the path to the image, but like the <img> tag, it supports the data URI.

For example, you can create a one-pixel red dot button as follows:

<input type="image" src="//static.base64.guru/uploads/images/1x1.gif" />

The same can be achieved by encoding image to Base64 and embedding it using data URI:

<input type="image" src="data:image/gif;base64,R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs" />

Both behaviors are identical — when you open the page, your browser displays the same image specified within <input> tag. The difference is that in the first case the browser sends one HTTP request to fetch the external image, when in the second case the image is already loaded in the browser’s memory and it does not need to send any HTTP requests.

Please note that Base64 Data URIs have some limitations. In addition, like almost any unconventional solutions, it has both advantages and disadvantages. Therefore, if you plan to use it, first of all, read about Base64 Data URI.

Comments (16)

I hope you enjoy this discussion. In any case, I ask you to join it.

  • Sam,
    Does anyone know how to add extent values to PNGBase64?
    • Administrator,
      Hey Sam! You cannot do that directly on Base64 string. You should decode Base64 to image, apply extent values, and encode the new image to Base64.
      • Sam,
        Thanks for the advice! How do I apply extent values to the Base64 image?
  • nqhXncMU,
    -1; waitfor delay '0:0:15' --
  • nqhXncMU,
    -5) OR 144=(SELECT 144 FROM PG_SLEEP(15))--
  • nqhXncMU,
    -5) OR 14=(SELECT 14 FROM PG_SLEEP(15))--
  • gBqsPxAZ,
    -1 OR 3+145-145-1=0+0+0+1 --
  • gBqsPxAZ,
    jRvDVJKT' OR 411=(SELECT 411 FROM PG_SLEEP(15))--
  • gBqsPxAZ,
    XnlMsfKJ') OR 986=(SELECT 986 FROM PG_SLEEP(15))--
  • nqhXncMU,
    555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
  • ncMUFCMU,
    -1' OR 2+426-426-1=0+0+0+1 --
  • ncMUFCMU,
    mTYGWXjw')) OR 939=(SELECT 939 FROM PG_SLEEP(15))--
  • nqhXncMU,
    1 waitfor delay '0:0:15' --
  • ncMUFCMU,
    WxqUcfDl')) OR 971=(SELECT 971 FROM PG_SLEEP(15))--
  • ncMUFCMU,
    1 waitfor delay '0:0:15' --
  • ncMUFCMU,
    if(now()=sysdate(),sleep(15),0)
Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.