Demystifying Clipboard

Punit Gupta
4 min readDec 27, 2020

--

A clipboard is probably one of the most common tools used by anyone using a computer or a mobile device, without really knowing it. It is the place on the system where data is store when you “copy” something — be it a piece of text from the New York Times, an image from Instagram, or a paragraph from MS Word. The same clipboard is used to get the data when performing a “paste” action. One of the amazing things about a clipboard is that it can store data copied from seemingly any software — Microsoft Word, Google Chrome, Adobe Reader, or even the good ol’ Terminal, and preserve the style and format to a good extent.

Working with Text data

To understand how it works, we will need the help of a Clipboard manager tool called CopyQ. It shows all the different formats in which the data is stored for a snippet of copied data.

Contents of the Clipboard when copying from a website on Google Chrome
Contents of the Clipboard when copying from a document in Microsoft Word.

Note the extended list of formats that we get when copying from Microsoft Word.

There are 3 types of applications we deal with when working on a personal computer — GUI-based application, CLI-based application, and Browser-based application. An example for each of these would be Microsoft Word, vim, and Google Docs respectively. There are 4 popular formats for storing text:

  1. text/html — It uses HTML tags and CSS styles to preserve the format of the text. It is primarily used when pasting to Google Docs, Google Sheets, etc.
  2. text/rtf — It uses Rich Text Format or RTF to preserve the format of the text. It is primarily used when pasting to MS Word, Wordpad, etc.
  3. application/pdf — It uses Adobe’s PDF format and text is stored as a binary image. It is primarily used when pasting to Google Docs or MS Word when either of the above formats is not available.
  4. text/plain — It keeps the text as it is without any formatting. It is primarily used when pasting to vim, iTerm, or when you choose “Paste without formatting” in MS Word or Google Docs.
    It is also used as a fallback in case the other 2 formats are not available.

The burden of providing the data in all of the 4 formats lies on the source software of the copied text.

For instance, if you copy text from Microsoft Word and it is somehow not able to provide you with the text/html version of the text, you cannot paste it into Google Docs with the same formatting. If you don’t have the text/plain version either, then you cannot paste the text at all.

Working with Image data

Clipboard stores images in a slightly different way. The data formats for images are far more diverse than text. The most commonly know formats are:

image/jpeg
image/png
image/bmp
image/gif

There are some other OS-specific formats like image/heic and image/tiff, which are only available for macOS.

Contents of the Clipboard when copying an image from a website on Google Chrome

Pretty much every image format can be used in Microsoft Word, Google Docs, and Whatsapp Web, which pops an interesting (or rather amusing) question — Why do we have so many different image formats?
The short answer to this is — it is all about size and quality. The best format to store images would be BMP, but it is not economical to use it for storage of Digital photos (an image stored as a 14KB JPEG file could take up to 8MB in BMP format). You could read more about image formats here on HowStuffWorks.

Working with other data formats

So far we have seen Text and Images. What about audio or video data?
The clipboard was designed during the days when Text and images were the only data formats. Even if we are able to inject audio data, say, using audio/ogg as format, we don’t have an application to “accept” or “render” pasted audio data. Some modern applications like FL Studio or Garageband, that let you copy and paste musical notes, achieve that by encoding and decoding the notes as Text data. Other applications like Audacity have a custom implementation to store audio snippets without the use of the generic clipboard.

Contents of the Clipboard when copying a sequence of notes from Game of Thrones title track in GarageBand

Feel free to drop your questions and feedback in the comments below.

--

--