The snippet library.
Small, practical examples. Search by task or narrow things down below.
Resolve a relative URL against a base
JavaScript: A trailing slash makes the final base path component a directory.
JavaScript✓ Tested
Resolve a relative URL against a base
TypeScript: A trailing slash makes the final base path component a directory.
TypeScript✓ Tested
Resolve relative links against an explicit base
HTML: A base href changes how relative document URLs are resolved.
HTML✓ Tested
Respect dark color preference
Apply different CSS colors when the browser requests a dark theme.
CSS✓ Tested
Respect reduced motion
Disable a CSS animation when the user prefers reduced motion.
CSS✓ Tested
Respond to a button click
jQuery: Learn how to respond to a button click in a complete browser example.
jQuery✓ Tested
Respond to the Enter key
jQuery: Use the event key rather than deprecated numeric key codes.
jQuery✓ Tested
Respond when a select value changes
jQuery: Learn how to respond when a select value changes in a complete browser example.
jQuery✓ Tested
Respond while a user types
jQuery: Learn how to respond while a user types in a complete browser example.
jQuery✓ Tested
Restart an existing container
Docker / Compose: restart starts the same container again while retaining its writable layer.
Docker / Compose✓ Tested
Restart numbering at an individual list item
HTML: A value on one ordered-list item sets its ordinal and affects following items.
HTML✓ Tested
Restore a file’s content from an older commit
Git: Specify a source revision when the desired contents are not in the current index.
Git✓ Tested