Tired of focus styles applying on mouse clicks? :focus-visible is the trick.

Category Image 091

Having focus styles for any interactive element is crucial on a website. Hidde de Vries:

Focus indicators make the difference between day and night for people who rely on them. […]

Focus outlines help users figure out where they are on a page. They show which form field is currently filled in, or which button is about to be pressed. People who use a mouse, might use their cursor for this, but not everyone uses a mouse. For instance, there are many keyboard users: a person with a baby on one arm, people with chronic diseases that prevent the use of a mouse, and of course… developers and other power users.

You don’t have to create your own :focus styles in CSS, although you can. By default, browsers apply their own styles to interactive elements. But if you don’t like that look, the temptation is to style your own. So if you do something like this, boom, we’ve got focus styles under our control:

button:focus {
  outline: 5px solid red;
}

(By the way, outline is a great friend to focus styles for reasons Manuel Matuzovic gets into.)

But by doing this, we’ve also done something else: we’ve made it so when you click (like with a mouse on a desktop computer, otherwise known as a fine pointer) those :focus styles apply to the element. This can be highly undesirable, leading to the CEO being all like why does the button change looks when I click it??? Fair enough, CEO, let’s fix it.

The trick is using :focus-visible which is relatively new but has pretty solid browser support. The whole point of it is applying focus styles that apply at all times an element takes focus, except when a fine pointer clicks it. Which is kinda perfect really. But if you’re nervous about going all-in on only using :focus-visible, a way to continue to use :focus styles too is to wrap them in an @supports block like:

@supports not selector(:focus-visible) {
    button:focus {
        
    }
}

Fortunately, the browser support for @supports and the selector() function is a bit better than :focus-visible, so this buys some additional browser support 🎉.

Pen:

The post Tired of focus styles applying on mouse clicks? :focus-visible is the trick. appeared first on CodePen Blog.

Bulk Actions for Assets

Featured Imgs 23

We got a support request from a user who had many thousands of uploaded files using our Asset Hosting feature. They told us many of them were duplicates and totally unused variations and they’d like to clean up. And to be perfectly honest, it was so many assets it was causing some minor bugs with search and actually find the assets they were trying to find.

So to assist in this cleanup, we decided to take a tiny break from our larger projects, and kick out this new feature: Bulk Actions for Assets. There isn’t all that much to understand, so here it is:

  1. You can select multiple assets at a time
  2. When do you…
  3. You can delete all of them, or
  4. You can download all of them.

Here’s me showing off those things:

Hopefully, it’s rather self-explanatory and you find it useful. We’d like to add more bulk actions for you for other things in time, so let us know if you have one in mind particularly.

The post Bulk Actions for Assets appeared first on CodePen Blog.

372: Trends

Typography Definitions Cover

This week Marie and Chris get together to chat about what’s been hot hot hot on CodePen lately. We’ve discovered there is a really taking to the creamy cardstock look, for one thing. Typography is always great, but we’re seeing more typographic trickery often including variable fonts. While not new, there are still loads of really wonderfully creative Pens using Three.js and p5.js. Neon-on-dark is a fresh look. We get into those and more, a bit sneakily as we can take an internal look at what the Top 100 might look like this year, but we can’t share those details too early!

Time Jumps

  • 00:24 Trending episode
  • 01:34 The web3 aesthetic
  • 03:33 Pen and ink on cardstock
  • 06:44 Variable fonts
  • 10:18 Ask the database what’s popping?
  • 11:42 Celebrating follower number
  • 12:49 ThreeJS and P5 processing
  • 20:08 Public documentation on what it takes to get picked
  • 26:33 CodePen Challenges

The post 372: Trends appeared first on CodePen Blog.

371: Jon Kantner

Category Image 052

I got to speak to Jon Kantner! Jon is an incredibly prolific creator, and I believe has the most appearances in the CodePen Spark of any creator. Like so many other creators I’ve talked to Jon also shares what he knows in a variety of ways, like writing (see his personal site, or articles he wrote when I ran CSS-Tricks). We got to chat about some of his iconic Pens, his work, and some past fascinations like Tweet-sized code experiments. Follow him on Twitter here.

Time Jumps

  • 00:26 Guest introduction
  • 02:44 What’s a day like as a front end dev?
  • 05:48 SVG Pens
  • 06:48 Skateboard spinner Pen
  • 10:38 Acrobatic tree loader
  • 11:50 Input progress Xmas Pen
  • 13:40 Writing about obsolete technology
  • 16:02 Code golfing
  • 19:25 Navigating without CSS
  • 21:22 What new web tech are you excited about?

The post 371: Jon Kantner appeared first on CodePen Blog.

370: Alex Trost

Featured Imgs 23

This week I got to speak with Alex Trost! Alex has been hard at work created Frontend Horse, a clever brand celebrating the beautiful and clever things in our industry via a newsletter, articles, streaming, a Discord community and more. This is the way to do it!

Time Jumps

  • 00:15 Guest introduction
  • 01:18 What is Frontend.Horse?
  • 06:35 Helping people unlock new technology through a newsletter
  • 11:22 The business angle to Frontend.Horse
  • 16:27 Sponsor: Notion
  • 17:29 History of Frontend.Horse
  • 20:21 Embracing Twitch
  • 22:42 Using Discord to build community
  • 30:56 Building on CodePen

Sponsor: Notion

Notion is an amazing collaborative tool that not only helps organize your company’s information but helps with project management as well. We know that all too well here at CodePen, as we use Notion for countless business tasks. Learn more and get started for free at notion.com/codepen. Take your first step toward an organized, happier team, today.

The post 370: Alex Trost appeared first on CodePen Blog.

One Weird Trick to Try @parcel/css on CodePen

Category Image 091

Ideally, we’d just offer @parcel/css as a CSS processor choice right in our editors. We could absolutely do that, but we’re smack in the middle of a bunch of next-gen CodePen stuff, and we’re keeping our efforts focused there. Never fear, interesting new processors like this will be there along with it. But this CSS processor caught my eye especially because it’s a very fresh, modern, and interesting take on CSS processing. It handles vendor prefixing on its own (something you might otherwise use Autoprefixer for), it handles “syntax lowering” (love that term) for future-syntax CSS (like you’d use postcss-preset-env for), offers scoping, and even has its own built-in minifier, while being super fast. Nice!

So what if you do wanna try it on CodePen? Well, it’s actually possible because they have cleverly released the processor with a Wasm option, not just a backend-language-only thing. So here’s the plan:

  1. Load the processor in the browser as a script (go Wasm go!)
  2. Pull the CSS from the current Pen
  3. Pass that CSS to the in-browser processor we just loaded
  4. Get the transformed CSS
  5. Replace the CSS in the preview with the transformed CSS

Check it:

The post One Weird Trick to Try @parcel/css on CodePen appeared first on CodePen Blog.

366: Paulina Hetman

Category Image 052

I got to talk to Paulina Hetman this week! Paulina is a heck of a creative coder, using her skills as an illustrator and all-around web developer to make ideas come to life. And she doesn’t keep all those ideas to herself, she spends time educating other budding developers both professionally and by building courses and things like her incredibly clever quizzes (as Pens!).

Time Jumps

  • 00:22 Guest introduction
  • 01:12 Making quizzes in pens
  • 05:17 Working with cascade layers
  • 06:20 Using CodePen for teaching
  • 08:38 Homepage design as a pen
  • 09:54 Sponsor: Notion
  • 10:47 Working with WordPress and Automattic
  • 13:23 Working with particles and three.js
  • 17:31 Working with illustrations
  • 19:29 Working with the syntax of CSS
  • 22:10 Horizontal parallax pen
  • 24:15 CSS Shapes forest collection
  • 26:22 Tagging Google fonts
  • 27:36 Landscape in a triangle pen
  • 27:51 When you can’t decide pen
  • 29:39 Header transition pen

Sponsor: Notion

Notion is an amazing collaborative tool that not only helps organize your company’s information but helps with project management as well. We know that all too well here at CodePen, as we use Notion for countless business tasks. Learn more and get started for free at notion.com/codepen. Take your first step toward an organized, happier team, today.

The post 366: Paulina Hetman appeared first on CodePen Blog.

365: Klare

Featured Imgs 23

Klare is moving on from design at CodePen to design at GitHub. Huge congrats Klare! If you didn’t know Klare was our one and only dedicated designer here at CodePen and left a massive mark here in the design and UX of CodePen, the app, as well as internally in our organization practices. I’m talking with Klare here just a few days before her last day to reflect on her years here.

Time Jumps

  • 00:25 Klare’s announcement
  • 01:40 What are some of your work highlights?
  • 04:01 Accessing your work
  • 05:26 Following social feeds on CodePen
  • 08:00 Designing at CodePen
  • 11:27 Leaving behind a design system
  • 14:06 Making incremental changes
  • 16:08 Sidebar nav for an app
  • 18:02 Homepage updates
  • 21:26 Using a common language for code design system
  • 25:35 Documentation and project management
  • 29:08 New job description

The post 365: Klare appeared first on CodePen Blog.

362: Chris Nager

Category Image 052

This week I got to speak with Chris Nager! I’ve known Chris quite a while. I remember being inspired by his hand-drawn SVG plus symbol and subsequent guide to <path> commands, which inspired my own shortly after I was properly obsessed with SVG. We talk about all sorts of things like accessibility, how far CSS has come, and some of the amazing stuff that has shipped recently in Safari Technical Preview. Check out Chris’ Twitter, personal site, and classic great project Give ‘n’ Go, a CodePen/Dribbble crossover website.

Time Jumps

  • 00:24 Guest introduction
  • 01:56 Hand drawing SVG
  • 04:07 Dribbble and CodePen
  • 06:55 Accessibility as a focus
  • 09:04 Color-contrast function
  • 11:30 Color mix function
  • 13:20 inert and letting trim
  • 15:37 Clamp function
  • 16:28 Accessibility and JavaScript or React
  • 22:12 Deploy previews are amazing
  • 28:31 CSS logical properties and values
  • 30:16 ThingUI
  • 33:34 Using ch

The post 362: Chris Nager appeared first on CodePen Blog.

361: Forks in a New Tab

Featured Imgs 23

If you Command (Mac) or Control (PC) click the Fork button, it will open the newly forked Pen in a new tab in your browser. That’s new behavior. Before, it would open the fork in the same tab, no matter how you click. That was unfortunate, as Cassie called out:

Why didn’t it work like this before? Well, that’s what Shaw and I get into in this podcast. It’s a smidge complicated. The root of it is that that Fork button isn’t a hyperlink. It’s a button handled by JavaScript because of the nature of how it works (a fork might have data that only the client knows about: unsaved code changes). But Shaw found a way to make it work anyway, by essentially passing the metaKey information through all the forking process until that moment we had an opportunity to open that new tab.

Time Jumps

  • 00:32 What was the request?
  • 03:37 Being careful with target="_blank"
  • 05:14 The whole forking process
  • 07:16 A form for example
  • 08:41 How forks work on a pen
  • 10:47 How did you pass the data?
  • 13:41 It’s behaving like a link
  • 15:29 Sponsor: Notion
  • 17:18 A few issues
  • 20:14 People forking instead of saving

Sponsor: Notion

Notion is an incredible organizational tool. Individuals can get a ton out of it, but I find the most benefit in making it a home base for teams. It can replace so many separate tools (documents, meeting notes, todos, kanbans, calendars, etc) that it really becomes the hub of doing work, and everything stays far more organized than disparate tools ever could.

The post 361: Forks in a New Tab appeared first on CodePen Blog.

Manuel Matuzovic’s CSS Specificity Demo

Category Image 052

If you’re looking for a primer on CSS specificity, we’ve got that. And if you’re trying to get ahead of the game, you should be aware of CSS Cascade Layers as well.

Screenshot of the CSS Specificity Demo.

One of the ways to help get a grasp of CSS specificity is thinking terms of “what beats what” or how strong the specificity is. Manuel Matuzovic has a helpful interactive step-by-step demo. You keep clicking the “Add selector” button, and the CSS shown (and applied to the page) changes with ever-increasingly-strong selectors applied to the body that change the background-color. At the end, it veers into not-really-selectors trickery, like using @keyframes to override things.

More specificity practice

If you enjoyed the trickery at the end, check out Francisco Dias’ A Specificity Battle!, an article we published a few years back that does a back-and-forth styling battle with nineteen steps “selecting” the same element to re-style it. CSS is cray sometimes.

To Shared LinkPermalink on CSS-Tricks


Manuel Matuzovic’s CSS Specificity Demo originally published on CSS-Tricks. You should get the newsletter.

355: With Adam Argyle

Category Image 052

I grabbed Adam intending to chat about all sorts of CSS stuff and his work at Google and on VisBug. But then we chatted pretty much the entire time about color and what’s coming there to the web platform.

Time Jumps

Sponsor: WordPress.com

WordPress.com is the fastest way to spin up a WordPress site. You’ll be able to build any sort of site around it to power your business or hobby. How do you make the most of it? Subscribe to their brand spankin’ new YouTube channel to learn more about using your site and what fellow customers are doing with theirs.

The post 355: With Adam Argyle appeared first on CodePen Blog.

353: With Louis Hoebregts

Category Image 052

Louis Hoebregts (aka Mamboleoo) has been creating wonderfully creative Pens on CodePen for many years. His early work, as we learn on this episode, was inspired by the CSS trickery of Lea Verou! He rotates his tools between HTML and CSS, SVG, and canvas, but tends to have an Aspect of motion and the unexpected. Some of the most popular Pens have an Aspect of education to them as well. Here’s a list of Louis’ Pens he chose to talk about, covering some of his history here, each of which is symbolic of a personal era and often unlocking new professional doors:

Time Jumps

  • 00:34 Guest introduction
  • 02:35 His first Pen
  • 05:21 Second Pen
  • 09:13 Sponsor: WooCommerce
  • 10:50 Animating a photo (2015)
  • 15:23 ThreeJS Pen
  • 18:26 Generative art and NFTs
  • 21:18 Turn your mind Pen
  • 25:11 Teaching code
  • 29:12 Try to have fun with code
  • 30:01 Happy New Year Pen
  • 32:42 CSS 3D Pen
  • 36:22 Running a Meetup
  • 40:48 Most popular Pen
  • 43:24 Among Us inspired Pen
  • 44:32 The Trick to Viewports in Mobile article

Sponsor: WooCommerce

WooCommerce can do it all as far as adding eCommerce functionality to a WordPress site. One off product sales, for sure, including shipping and inventory management and all that. But it can also sell digital products. It can also sell memberships and subscriptions. Put on your what if hat. What if your business sold memberships? What could you offer? It’s always worth thinking about.

The post 353: With Louis Hoebregts appeared first on CodePen Blog.

Metaphors We Web By

Category Image 052

Maggie Appleton gets into what is perhaps the foremost metaphor the web is founded on: paper.

Paper documents were the original metaphor for the web. […]

The page you’re reading this on still mimics paper. We still call it a page or an HTML document. It follows the same typographic rules and conventions – black text on white backgrounds and a top-to-bottom / left-to-right heirarchical structure.

Over in the ShopTalk Discord, the idea of CSS custom properties named --ink and --paper came up the other day as abstractions for color and background-color and I kinda like it. There’s something more clear about the meanings of those terms to me.

But Maggie gets into some of the downsides of the paper-based metaphors, pointing out Ted Nelson’s critiques. This is interesting:

We treat the page as the smallest unit of linkable information, instead of the sentence or paragraph.

That kind of ignores the idea of jump links or Chrome’s new-ish link to highlight, but I take the point.

Will the main metaphor of the web as paper change in time? I’d say it’s highly likely. The interactivity and behavior we expect on the web today is a million miles different than we expected in the past and that’s going to keep happening. These updates accelerate the change. Perhaps someday the metaphors will have shifted to “alternate neighborhood,” “second brain,” or “dedicated assistant.”

To Shared LinkPermalink on CSS-Tricks


Metaphors We Web By originally published on CSS-Tricks. You should get the newsletter and become a supporter.

8 Interesting Typography Links for January 2022

Typography Definitions Cover

Every now and then, I find that I’ve accumulated a bunch of links about various things I find interesting. Typography is one of those things! Here’s a list of typography links to other articles that I’ve been saving up and think are worth sharing.

A specimen of the Retail typeface, once of the typography links in the list.
An awesome new font from OH no Type Company

Do you have any interesting typography links from the past month worth sharing? Drop ’em in the comments!


8 Interesting Typography Links for January 2022 originally published on CSS-Tricks. You should get the newsletter and become a supporter.

Should CSS Override Default Browser Styles?

Category Image 052

CSS overrides can change the default look of almost anything:

  • You can use CSS to override what a checkbox or radio button looks like, but if you don’t, the checkbox will look like a default checkbox on your operating system and some would say that’s best for accessibility and usability.
  • You can use CSS to override what a select menu looks like, but if you don’t, the select will look like a default select menu on your operating system and some would say that’s best for accessibility and usability.
  • You can override what anchor links look like, but some would say they should be blue with underlines because that is the default and it’s best for accessibility and usability.
  • You can override what scrollbars look like, but if you don’t, the scrollbars will look (and behave) the way default scrollbars do on your operating system, and some would say that’s best for accessibility and usability.

It just goes on and on…

In my experience, everyone has a different line. Nearly everybody styles their buttons. Nearly everybody styles their links, but some might only customize the hue of blue and leave the underline, drawing the line at more elaborate changes. It’s fairly popular to style form elements like checkboxes, radio buttons, and selects, but some people draw the line before that.

Some people draw a line saying you should never change a default cursor, some push that line back to make the cursor into a pointer for created interactive elements, some push that line so far they are OK with custom images as cursors. Some people draw the line with scrollbars saying they should never be customized, while some people implement elaborate designs.

CSS is a language for changing the design of websites. Every ruleset you write likely changes the defaults of something. The lines are relatively fuzzy, but I’d say there is nothing in CSS that should be outright banned from use — it’s more about the styling choices you make. So when you do choose to style something, it remains usable and accessible. Heck, background-color can be terribly abused making for inaccessible and unusable areas of a site, but nobody raises pitchforks over that.


Should CSS Override Default Browser Styles? originally published on CSS-Tricks

Defensive CSS

Category Image 052


Ahmad Shadeed nails it again with “Defensive CSS.” The idea is that you should write CSS to be ready for issues caused by dynamic content.

More items than you thought would be there? No problem, the area can expand or scroll. Title too long? No problem, it either wraps or truncates, and won’t bump into anything weird because margins or gaps are set up. Image come over in an unexpected size? No worries, the layout is designed to make sure the dedicated area is filled with image and will handle the sizing/cropping accordingly.

There is no such thing as being a good CSS developer and not coding defensively. This is what being a CSS developer is, especially when you factor in progressive enhancement concepts and cross-browser/device unknowns.

To Shared LinkPermalink on CSS-Tricks


Defensive CSS originally published on CSS-Tricks