Code Snippets
A catalog of short, reusable code examples. Pick a language and find snippets you can drop into your project.
Each section below focuses on one language. You get one clear task per snippet—for example, “reverse a string in Python” or “check if a string contains a substring in PHP”—with working code and a brief explanation. No long tutorials: copy the code, adapt it to your case, and move on. If you’re new to programming, start with Learn to Code for Python and JavaScript, then come back here to browse by topic.
How we organize snippets
Snippets are grouped by language: HTML, JavaScript, jQuery, PHP, and Python. On each language page you'll find several full examples with code blocks and short explanations. We focus on tasks developers search for often: string and array operations, DOM changes, form handling, file and date operations. Every example is self-contained so you can paste it into your project and adjust variable names or logic as needed.
By language
What’s in each section
HTML
Structure, forms, scrollable divs, disabled checkboxes, background images, dropdowns, and semantic markup. Valid HTML5; combine with your own CSS and JavaScript for interactivity.
JavaScript
DOM updates, string and number helpers (round to 10, remove vowels, pad numbers), event handlers, and image rotation. Vanilla JS only; see jQuery for the same ideas in jQuery.
jQuery
Selectors, cloning, delay(), disabling buttons, changing label text, and form events. For legacy or jQuery-based projects.
PHP
Strings (contains, trim), arrays (unique, reindex), dates (month from date), and common checks. PHP 7.4+ with notes for PHP 8.
Python
Strings (reverse, slice), dicts (empty check), files (line count), math (nth root), and small patterns. Python 3; run in REPL or scripts.
New to coding? Start with Learn to Code. Need a different language or topic? Check back—we add new snippets regularly.