Chris’ Corner: Switch

Category Image 052

The “switch” is a pretty common design pattern on the web. It’s pretty much a checkbox. In fact, under the HTML hood, it really ought to be an <input type="checkbox"> or perhaps a <select> with just two <option>s (or a third if there is an indeterminate state).

But unfortunately, the web doesn’t give us any primitive that looks particularly switch-like, as in, some kind of knob that is flipped one way or the other. So we use CSS. For example, we hide the checkbox one way or another, making sure there is still a discoverable clickable area, then with the :checked selector, style something that looks switch-like.

Here’s a very classic example.

Marcus Burnette nicely re-creating the iOS toggle look

I’m sure you could imagine using that for, say, toggling email notification settings on an off for some sort of app. We use them here on CodePen quite a bit, for stuff like toggling the privacy of a Pen. Or you might use a toggle to switch a site between dark mode and light mode.

Speaking of that, Aleksandr Hovhannisyan has a solid article about the struggles of a dark mode toggle. You’d think it would be pretty straightforward, but it really isn’t. Consider that users have system-level preferences in addition to your site-level preference, and you have to honor them in the proper order. Plus you have to set the controls properly as well as actually style the site accordingly, ideally without temporarily flashing the wrong colors. (FART). Aleksandr does a good job of it and links to other posts that have done a similarly good job. It’s always way more code than you want it to be, leading me to think browsers and standards could and should get more involved, but I also admit I don’t have a perfect idea on what they should do. Chrome has played with Auto Dark Mode, but it’s not clear how that trial went. (And speaking of Dark Mode, this gallery is pretty nicely done.)

Anyway, I was trying to talk about switches!

I saw Jen Simmons note that Safari is playing with a native switch. Here’s the HTML:

<input type="checkbox" switch>

Nice.

And here’s what it looks like by default:

No big surprise there! It’s the native iOS toggle come to life. It respects accent-color in CSS like other form controls, which is great. But better, it has really sensible pseudo elements you can grab and style. You get ::thumb and ::track elements (nice clear naming) plus ::before and ::after work on the element itself, so there are a lot of possibilities.

.custom-switch { }
.custom-switch::thumb { }
.custom-switch::track { }

.custom-switch:checked::thumb { }
.custom-switch:checked::track { }

.custom-switch::checked::after { }
.custom-switch::checked::before { }

Tim Nguyen has demos that do a good job of showing off the possibilities with clean readable CSS.

The best part of browsers providing this kind of thing for us, to me, is that now you don’t have to worry about dinking up the accessibility. Now, as long as you follow the normal HTML structure of a labelled checkbox in a form, you’re good. No worries about the way you hid the original checkbox screwing things up. You are taking visual control though, so do take care to make sure the checked and unchecked values are at least as clear as a checked or unchecked checkbox.

Dot Product, Euclidean Distance, and Cosine Similarity in SingleStoreDB

Featured Imgs 23

SingleStoreDB has supported vector functions since 2017. In this article, we'll see examples of using Dot Product, Euclidean Distance, and Cosine Similarity in SingleStoreDB to assess vector relationships. New vector capabilities will be available in the next major release of SingleStoreDB - stay tuned.

The Dot Product

The Dot Product is a mathematical procedure combining two numbers lists into a single value. This is achieved by multiplying corresponding numbers from each list and then adding up the products. This operation is useful for tasks like measuring the commonality between two sets of values or assessing the influence of one set on another.

All-In-One Security (AIOS) Release 5.2.5: UI Improvements

Featured Imgs 09
The new release from AIOS has improved key features of the UI, leading to a smoother experience and a more intuitive, easy to use interface for users. Important elements which have been updated include a complete overhaul of the scanner page, as well as a number of new user interface widgets. Multiple admin menus have […]

Setting Up a WordPress Test Environment With wp-env

Featured Imgs 23

As I worked through the homework challenge round at one of the companies I interviewed at (a company that was very WordPress centric), I found myself struggling with literally every step – trying to find shreds of information on how to do the most basic things. Things like building a simple local test environment.

I found information telling me I could use:

Exploring the Security Risks of Large Language Models

Featured Imgs 23

According to a recent survey, 74% of IT decision-makers have expressed concerns about the cybersecurity risks associated with LLMs, such as the potential for spreading misinformation.

The world of Artificial Intelligence (AI) is booming with new capabilities, mainly owing to generative AI and its popular subset—Large Language Model (LLM).

Unlocking Data Dynamics: Understanding the Power of Pivoting and Un-Pivoting

Featured Imgs 23

In the realm of data manipulation and analysis, the terms "pivoting" and "un-pivoting" play crucial roles in transforming raw data into meaningful insights.

These operations are fundamental to reshaping datasets for better visualization, analysis, and interpretation. In this blog post, let's kick back, sip some coffee, and demystify these concepts that make your data dance to the right tunes.

Breaking Support and Engineering Barriers With Team Collaboration

Featured Imgs 23

In today’s dynamic digital landscape, where operations are ever-growing and teams are getting more diverse, collaboration is key to achieving business success. As per a McKinsey report, innovative business collaboration techniques can improve your company’s productivity by 20-30%. 

However, as your business scales, teams begin to drift apart from one another, leading to miscommunication and organizational silos. This results in employee burnout and contributes significantly to disjointed customer experiences. 

How to Improve Team Performance: 11 Effective Ways

Featured Imgs 23

It's pretty common to hear that managers are responsible for the team's top performance, isn't it?

But we managers know how difficult it is to make everyone work together without much fuss. Especially when you have someone with unique characteristics on the team, your job can become a little more tricky.    

What are the high-value, long-tail keywords relevant to our industry?

Featured Imgs 20

Here's a general process to find relevant long-tail keywords:

  1. Understand Your Business and Audience:
    Identify the core products, services, or topics related to your business.
    Understand the needs, pain points, and interests of your target audience.
  2. Brainstorm Seed Keywords:
    Begin with a list of seed keywords related to your business. These are the primary terms that describe what you offer.
  3. Use Keyword Research Tools:
    Utilize keyword research tools to expand your list and discover long-tail keywords.
    Google Keyword Planner: Provides insights into search volume and competition.
    SEMrush, Ahrefs, Moz: Offers in-depth keyword research and competitor analysis.
  4. Look for Long-Tail Variations:
    Long-tail keywords are more specific and often have lower competition.
    For example, if your business is in the fitness industry, consider long-tail variations like "best home workouts for beginners" or "healthy meal prep ideas for weight loss."
  5. Consider User Intent:
    Think about the intent behind the searches. What questions or problems might users have that your content can address?
    Long-tail keywords often reflect specific user intent

Digital marketing for small businesses?

Featured Imgs 20

Digital marketing offers tremendous opportunities for small businesses to reach and engage with their target audience in a cost-effective and measurable way. Here are some of the ways that small businesses can benefit from digital marketing:

(1) Increased visibility: With digital marketing, small businesses can reach a wider audience than traditional marketing methods, such as print ads or billboards. By using search engine optimization (SEO), pay-per-click (PPC) advertising, and social media marketing, small businesses can increase their online visibility and attract more customers.
(2) Targeted advertising: Digital marketing allows small businesses to target specific demographics, interests, and behaviors to reach their ideal customers. This means that small businesses can reach people who are most likely to be interested in their products or services and avoid wasting money on ineffective advertising.
(3) Cost-effective: Digital marketing can be significantly more cost-effective than traditional marketing methods, especially for small businesses with limited budgets. Many digital marketing tactics, such as email marketing and social media marketing, are relatively inexpensive and can offer a high return on investment (ROI).
(4) Measurable results: Digital marketing provides measurable data that allows small businesses to track their marketing efforts' effectiveness. With analytics tools, small businesses can track website traffic, conversion rates, and other key performance indicators (KPIs) to optimize their marketing strategies continually.