6 Useful Bookmarklets To Boost Web Development | CSS-Tricks (2024)

DigitalOcean provides cloud products for every stage of your journey. Get started with $200 in free credit!

A bookmarklet is a JavaScript-based bookmark that adds to a web browser. I’d like to show you some awesome web browser hacks to aid your web development workflow and how to convert those hacks into time-saving bookmarklets.

  1. Activating design mode
  2. Applying a background to everything
  3. Simulating events
  4. Setting cookies
  5. Toggling classes
  6. Color widget bookmark
  7. What other bookmarklets can you think of?

Activating design mode

Design mode (styled as designMode since it’s a JavaScript property) is for who like to experiment with variations of copy on a live website. For example, copywriters who like to observe how content reads within the flow of the website’s design, or, say, designers who want to ensure that text fits comfortably within a certain space at a certain font size.

JavaScript has a mightily simple feature that can render an entire HTML document editable. It works exactly like HTML’s contenteditable="true" name-value attribute (or contentEditable="true" in JavaScript) but for the whole document. If you’d like to see how it works, start by entering the browser’s console using the relevant keyboard shortcut:

  • Chrome: Option + + J / Shift + CTRL + J
  • Firefox: Option + + K / Shift + CTRL + K
  • Safari: Option + + C / Shift + CTRL + C

Next, type document.designMode="on" into the console, hit Return, and then click on any text element. You’ll see that this text element (and all other text elements) are now editable simply by clicking on them. This method of editing text on a live website is much faster than having to open DevTools, then right-clicking and selecting the “Edit Text” option… and much less tiresome.

6 Useful Bookmarklets To Boost Web Development | CSS-Tricks (1)

While I’m not sure that “design mode” is the most accurate description of the feature, it’s super useful nonetheless and it’s actually been around for a really long time, surprisingly.

And what’s even an even faster way to enable it? A bookmarklet, of course! Create a bookmark using javascript: document.designMode="on";void 0; as the URL.

6 Useful Bookmarklets To Boost Web Development | CSS-Tricks (2)

Applying a background to everything

When HTML elements don’t have backgrounds, it can be difficult to visualize their bounds and/or accurately measure the distance between them and other elements. Developers might want to better visualize bounds when dealing with optical imbalance (i.e. when something “looks off” even though it’s not), margin collapse (when certain margins are ignored), various issues with display:/float:/position:, and more.

Applying backgrounds means applying a semi-transparent background to all HTML elements in order to better visualize their bounds and spacings. It’s something many of us commonly do by opening up DevTools then typing a CSS declaration like selector { background: rgb(0 0 0 / 10%); } into the “Styles” box. But again, it’s really tiresome and repetitive — and something we can simplify with a bookmarklet.

Once again, to create a bookmark, we’re going to make a URL. Here’s what we can use for this one:

javascript: document.querySelectorAll("*").forEach(element => element.style.background="rgb(0 0 0 / 10%)");

We’re using a semi-transparent background because the transparency stacks, which ensures that every nested element is distinguishable and the distances between them can be measured.

6 Useful Bookmarklets To Boost Web Development | CSS-Tricks (3)

Simulating events

Have you ever had to test a web event that first requires a series of interactions, or certain conditions to be met? It’s super time-consuming to have to test or debug these kinds of functionalities. This event simulation bookmarklet can be used to instantly trigger specific events, making testing a breeze.

Simulating an event means coding a “throwaway” button that triggers a JavaScript event, making it much easier to quickly and repeatedly test the event without having to meet any usual user-facing conditions, like needing to be logged in.

Assuming that you have your JavaScript event listeners set up, create a bookmark for each event that you’d like to trigger/simulate and submit the following URL:

javascript: document.querySelector("SELECTOR").click();

Replace “SELECTOR” with your unique selector, replace “click” with “focus” or “blur” (when necessary), or extend the snippet to make it trigger more complex events, like scroll.

Setting cookies

Cookies are tokens that are stored on a website visitor’s computer by the website that they’re visiting. Cookies contain data that can be read by the website that created them until they’ve exceeded their expiration date or have been deleted. The mere existence of a cookie can determine whether or not a visitor is logged in, whereas the data itself can store user information.

An example of a scenario where you might want to set a cookie using a bookmarklet is when you want to force a logged-in state during website testing. Websites often look very different for users that are logged in, however, logging in and out eventually becomes very tedious, so this bookmarklet can save quite a bit of time.

Manually writing expires= dates for cookies is awkward as heck, but luckily this create-your-own-set-cookie-bookmarklet app can generate a bookmarklet for a specific cookie, if you know its exact name.

Toggling classes

You may want to add or remove a class from an HTML element in order to trigger a fresh state or a change in appearance, otherwise known as toggling classes. Class toggling happens behind the scenes of most live websites, but it can also be used during testing to skip having to meet certain user-facing conditions.

Class toggling can be used to trigger changes in appearance (e.g. alternative themes or states) and even animations, but it can be a little fiddly when doing it with developer tools when it’s only for testing reasons (i.e. the website doesn’t actually function that way for users). Similar to the other bookmarklets, use this one to rapidly toggle classes and save yourself time.

Create the following bookmarklet to target all elements that match your chosen “SELECTOR”, which, in turn, toggles the “CLASS.”

javascript: document.querySelectorAll("SELECTOR").forEach(element => element.classList.toggle("CLASS"));

Color widget bookmark

While not technically a “bookmarklet,” this bookmarkable data URI by Scott Jehl opens up an <input type="color"> in a new tab:

So hey here’s my new color picker app!
It’s um, just an HTML color input wrapped in a data URI so I can bookmark it. (Feel free to do so yourself):

data:text/html;charset=utf-8,%3Chtml%3E%3Ctitle%3EColor Picker%3C%2Ftitle%3E%3Cinput type%3D”color”%3E%3C%2Fhtml%3E pic.twitter.com/0QyFqAsUSq

— Scott Jehl (@scottjehl) August 19, 2021
data:text/html;charset=utf-8,%3Chtml%3E%3Ctitle%3EColor Picker%3C%2Ftitle%3E%3Cinput type%3D"color"%3E%3C%2Fhtml%3E

Why is that cool? Well, how many times have you needed to grab a color value off a page, only to find yourself cracking open DevTools, clicking through a bunch of elements, and pouring over CSS properties to find the value? Better to run this little guy, click the element, and get a color right away!

What other bookmarklets can you think of?

Are there any overly repetitive web development workflows that require you to use the web browser’s sometimes-awkward developer tools? If so, it’s super easy to create your own time-saving bookmarklets. Just remember to start the URL with javascript:!

And if you’ve made a bookmarklet to simplify your workflow, I’d love to see it! Share them here in the comments and let’s get a nice collection going.

6 Useful Bookmarklets To Boost Web Development | CSS-Tricks (2024)
Top Articles
What Shots Does My Cat Need? A Guide to Feline Vaccines
Pet Vaccines: Schedules for Cats and Dogs
Formulaire 3CEp - COPRAUDIT
Why Does It Say I Have 0 Followers on TikTok?
Uber Hertz Marietta
Cold War Brainpop Answers
Bingo Bling Promo Code 2023
Update | Een maand afvallen met NBFM (+ recept & snacktips!) - Mama's Meisje
Craigslist Farm And Garden Yakima Wa
Top Scorers Transfermarkt
The Closest Dollar Store To My Location
Shahala Middle School Shahala Middle School Student Handbook
Cbs Local News Sacramento
Craigslist Apartments In Philly
1102 E Overland Trail Abilene 79601
9192464227
Amanda Balionis makes announcement as Erica Stoll strides fairways with Rory McIlroy
Stolen Touches Neva Altaj Read Online Free
Aaf Seu
MLB The Show 23 Marketplace: Your Ultimate Guide to Trading and Collecting - Belvidere Youth Baseball
Xxc Renegade 1000 Xxc Price In India Price
Hdtoday.comtv
Indian Restaurants In Cape Cod
Christmas Song Figgerits
One Piece Chapter 1077 Tcb
The Tragic Death Of Nikki Catsouras: The Story Behind The Viral Photos
Master Series Snap On Tool Box
Pirates Point Lake Of The Ozarks
Harris Teeter Weekly Ad Williamsburg Va
Seconds Valuable Fun Welcoming Gang Back Andy Griffith's Birthday A Top Wish So A Happy Birthday FZSW A Fabulous Man Kevin Talks About Times From Ten Day Weekend Fun Labor Day Break
Bayada Bucks Catalog 2023
Greet In Cheshire Crossword Clue
Etfcu Routing Number
Craigslist Chicagoland Area
Examination Policies: Finals, Midterms, General
Itsfunnydude11 Wisconsin Volleyball Team : Itsfunnydude11 Twitter, Itsfunnydude11 Reddit – Know About It ! - Opensquares
San Bernardino Pick A Part Inventory
Kayak Parts Amazon
The Abduction of Heather Teague
Nikki Porsche Girl Head
Help with Finding Parts for Your Vehicle
What Is The Solution To The Equation Below Mc010-1.Jpg
Ftbt Ugly God Lyrics
House Party 2023 Showtimes Near Mjr Chesterfield
Craigslist For Port Huron Michigan
Patriot Ledger Obits Today
Sour Power OG (Karma Genetics) :: Cannabis Strain Info
Walmart Supercenter Curbside Pickup
Craigslist Antelope Valley General For Sale
Tinfoil Unable To Start Software 2022
When His Eyes Opened Chapter 191
Mri Prospect Connect
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 5476

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.