Snippet

Snippet

A snippet is a short, reusable excerpt from a text or from program code. The term appears both in developer tools and in search engines, where it refers to the short text preview shown under a search result.

The English word “snippet” translates to a small cut-out piece. It refers to a short piece of text that has been cut out of a larger whole. In technology, the word is used in two meanings. One is familiar to everyone from search engines: below each result there are two to three lines of text from the page, so you can see in advance what it’s about. The other meaning comes from programming: there, a snippet is a small, ready-made building block of instructions for the computer that can be used again and again instead of typing it out each time. Both meanings share the same core — a small excerpt that is already useful on its own.

Small building blocks, big time savings

Programming largely consists of repetition. Certain routines are needed again in almost every project: reading in a file, iterating through a list, converting a date into another format. Writing these building blocks anew each time costs time and creates errors. Snippets solve this problem by storing the tested building block once and then inserting it again with just a few keystrokes.

A second advantage is consistency. When ten people work on a program and all use the same building block, the code looks the same everywhere. This makes it easier to read and easier to maintain. Large companies therefore maintain their own collections of vetted snippets, similar to a library of approved components.

For search engines, the meaning is an economic one. The snippet text often decides whether someone clicks on a result or on the one below it. For news sites and online shops, measurable revenue depends on it. There is an entire profession dedicated to exactly this: search engine optimization, or SEO for short.

From placeholder to finished code

In a code editor, a snippet is stored under a short abbreviation. If you type “for” and press the Tab key, for example, the program immediately inserts the complete basic structure of a loop. Many snippets contain placeholders: marked spots where something still needs to be entered. Pressing Tab jumps from placeholder to placeholder so they can be filled in.

In search engines, the snippet is created automatically. The search engine looks through the page for the passage that best matches the search query and cuts out about 150 to 160 characters from it. The searched words are shown in bold. Anyone who runs a website can provide a suggested text, the so-called meta description. But it is only a suggestion: if it doesn’t match the query, the search engine ignores it and cuts the text itself.

It is important to distinguish this from a library. A library is finished program code that is included from outside and remains an independent piece of software. A snippet, by contrast, is copied directly into one’s own text and afterwards becomes a completely normal part of it. If the template changes later, the inserted copies do not change along with it — this is easily overlooked.

Snippets in editors, search results, and chatbots

Snippets are most commonly encountered in programs like Visual Studio Code or on the code platform GitHub, where a dedicated feature called Gists stores snippets for sharing. The principle also exists outside of programming: email programs and chat tools offer text blocks for replies that are written over and over again.

At Google, a special form is called a Featured Snippet. Here, the search engine shows a box at the very top with a direct answer to the question. For website operators, this is a double-edged sword. The placement is highly visible, but many users read the answer and don’t click through any further.

In AI coverage today, the term appears in a third context. Assistants like ChatGPT or GitHub Copilot often output their answers as ready-made code snippets that can be adopted directly. Experts warn against using such snippets without checking them. They can contain errors or open security vulnerabilities, and anyone who doesn’t understand them will only notice once something goes wrong.

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.