Technology News

My Dumbest CSS Mistakes

We all make mistakes in our code. It happens! I know if I had one of those “Days Since Last Mistake” signs hanging over my desk, a big ol’ goose egg would be hovering above me all the time. It doesn’t have to be big mistakes, either. My clumsy self has committed small errors to repos ranging from typos all the way to complete npm module directories.

Whooooooops.

That’s one of the things I really love about CSS: it’s forgiving as heck. If it doesn’t understand a typo, it keeps looking up the cascade in search of a match. None of that stuff where one out of place characters breaks a site and takes no prisoners. But it’s still embarrassing when CSS mistakes pop up!

Like this one I find myself making way more times than I’d like to admit:

.element { display: flexbox; /* ????‍♂️ */
}

Or when I try setting a gradient without a background property:

.gradient { linear-gradient(45deg, rgb(50% 100% 90%), rgb(62% 85% 93%));
}

I hate how close X and C are on a keyboard because I can’t count how many times I’m blazing through something and mistake px for pc units.

.element { font-size: 16pc; /* I meant pixels! */
}

Another CSS mistake I catch every so often is one I know many other folks make because I spot it too often in blog posts with code snippets:

// This is not a CSS comment.
.element { /* This is a CSS comment. */
}

Have you ever forgotten to use var() around a CSS variable? I sure have.

.element { color: --primary-color;
}

Speaking of CSS variables, naming them is hard (like everything else) and I often use some incorrect version of a variable that I named!

:root { --color-primary: #FF5722; --color-secondary: #3E2723;
} /* Much later on... */ .element { color: var(--primary-color); /* ???? */
}

Yes, I have indeed copied a snippet of CSS before only to have fancy quotes get in the way of making it work:

.element::before { content: “”; /* Should be "" */
}

And, yes, I have spent way too long figuring out those quotes were the culprit.

Looking at that last one reminds me that I sometimes forget to set the content property when I’m working with ::before or ::after. Which reminds me of how I’ve forgotten to set an element’s position before trying to offset it or change its z-index. Seriously, these things happen!

It’s hard talking about mistakes

Have you ever finished reading some blog post sharing some amazing trick and felt some sort of Imposter Syndrome? I think that’s largely because blog posts often mask the real work — and failures — that go into amazing tricks. As someone who reads posts like that for a living, I can tell you that many, if not the vast majority, go through many rounds of editing where potentially embarrassing mistakes are weeded out and smoothed over.

Even those ridiculously awesome articles have to fail before they get all those ooooos and ahhhhhs.

The same is true of any app, website, demo, or whatever you happen to come across. The chances any of them came out perfect the first time is next to nothin’.

But if I’m being totally honest with you, I’m often more amazed (and interested) in the journey it takes to accomplish something, warts and all. The journey is a glimpse into what it’s like to think like a front-end developer. That’s where real (and most valuable) learning happens.

And all of this is merely building up to what I really want to ask…

What are your dumbest CSS mistakes?

C’mon, we all know you’ve made some! Let us learn from them!

SFMC Automation Best Practices to Beat the Competitive Bottleneck in Email Marketing
Help Shape the Future of CSS-Tricks!

Related Articles

5 Best And Fast Small-Business Loans

5-best-and-fast-small-business-loans
Are you planning to start your venture, or do you want to grow your business? Don’t know how to get the funds? The best way to fund your business is…

How to Build Effective Buyer Personas

how-to-build-effective-buyer-personas
Increasingly, and especially with the events of the first half of 2020, we are seeing a definitive shift to a more customer-centric culture. It is no longer about the value…

Quick Tip: How to Filter Data with PHP

Quick Tip: How to Filter Data with PHP
In this article, we’ll look at why it’s so important to filter anything that’s incorporated into our applications. In particular, we’ll look at how to validate and sanitize foreign data…

How to Create Shapes in CSS

how-to-create-shapes-in-css
In today’s tutorial, let’s create a simple list of the most common shapes that can be created using CSS3. We will make progress through the article and at the end, you…

To Stop AI-Powered Adversaries, Defenders Must Fight Fire with Fire

Exploring the Potential of the Metaverse: A New World Awaits
Anthropic’s Threat Intelligence team recently uncovered and disrupted a sophisticated nation-state operation that weaponized Claude’s agentic capabilities and the Model Context Protocol (MCP) to orchestrate automated cyberattacks simultaneously against multiple…