Search
Differential Serving
1.4.2019
There is "futuristic" JavaScript that we can write. "Stage 0" refers to ideas for the JavaScript language that are still proposals. Still, someone might turn that idea into a Babel plugin and it could compile into code that can ship to any browser. For some of these lucky proposals, Stage 0 becomes...
JavaScript Glossary: String length
26.3.2019
Basics
The length property of the String object returns the number of code points in a string object. It indicates the length of the string
Understanding Event Emitters
26.3.2019
Consider, a DOM Event:
const button = document.querySelector("button");
button.addEventListener("click", (event) => /* do something with the event */)
We added a listener to a button click. We’ve subscribed to an event being emitted and we fire a callback when it does. Every time we click that...
All About mailto: Links
22.3.2019
You can make a garden variety anchor link (<a>) open up a new email. Let's take a little journey into this feature. It's pretty easy to use, but as with anything web, there are lots of things to consider.
The basic functionality
<a href="mailto:someone@yoursite.com">Email...
Planning for Responsive Images
13.3.2019
The first time I made an image responsive, it was as simple as coding these four lines:
img {
max-width: 100%;
height auto; /* default */
}
Though that worked for me as a developer, it wasn’t the best for the audience. What happens if the the image in the src attribute is heavy? On high-end...
Smooth Scrolling for Screencasts
13.3.2019
Let's say you wanted to scroll a web page from top to bottom programmatically. For example, you're recording a screencast and want a nice full-page scroll. You probably can't scroll it yourself because it'll be all uneven and jerky. Native JavaScript can do smooth scrolling. Here's a tiny snippet...
Downsides of Smooth Scrolling
11.3.2019
Smooth scrolling has gotten a lot easier. If you want it all the time on your page, and you are happy letting the browser deal with the duration for you, it's a single line of CSS:
html {
scroll-behavior: smooth;
}
I tried this on version 17 of this site, and it was the second most-hated thing...
A Bit of Performance
28.2.2019
Here’s a great post by Roman Komarov on what he learned by improving the performance of his personal website. There’s a couple of neat things he does to tackle font loading in particular, such as adding the <link rel="preload"> tags for fonts. This will encourage those font files...
Did you know that CSS Custom Properties can handle images too?
27.2.2019
So you might be aware of CSS Custom Properties that let you set a variable, such as a theme color, and then apply it to multiple classes like this:
:root {
--theme: #777;
}
.alert {
background: var(—-theme);
}
.button {
background: var(—-theme);
}
Well, I had seen this pattern so often...
The Ultimate Guide to JavaScript Algorithms: Pig Latin
26.2.2019
“Pig Latin is a constructed language game in which words in English are altered, usually by adding a fabricated suffix or by moving the initial consonant or consonant cluster of a
Colorful Typographic Experiments
21.2.2019
There have been some interesting, boundary-pushing typography-related experiments lately. I was trying to think of a joke like "somethings in the descenders" but I just can't find something that will stand on its own leg without being easy to counter.
Codrin Pavel created a fascinating multi-color...
Social Cards as a Service
19.2.2019
I love the idea of programmatically generated images. That power is close at hand these days for us front-end developers, thanks to the concept of headless browsers. Take Puppeteer, the library for controlling headless Chrome. Generating images from URLs is their default use case:
const puppeteer...
Where Do You Nest Your Sass Breakpoints?
11.2.2019
I love nesting my @media query breakpoints. It's perhaps the most important feature of Sass to me. Maybe I pick a method and do it like this:
.element {
display: grid;
grid-template-columns: 100px 1fr;
@include breakpoint(baby-bear) {
display: block;
}
}
That's straightforward enough....
JavaScript Glossary: Array .push() Method
8.2.2019
Basics
This methods appends one or more value to the last position of an array. This method mutates the array returning the new length of the array.
let
JavaScript Glossary: Array .forEach() Method
8.2.2019
Basics
The forEach() method takes a function that performs an action on each of the elements in this array.
[1, 2, 3, 4, 5].forEach(functio
How do you figure?
1.2.2019
Scott O'Hara digs into the <figure> and <figcaption> elements. Gotta love a good ol' HTML deep dive.
I use these on just about every blog post here on CSS-Tricks, and as I've suspected, I've basically been doing it wrong forever. My original thinking was that a figcaption was just...
Using Artificial Intelligence to Generate Alt Text on Images
1.2.2019
Web developers and content editors alike often forget or ignore one of the most important parts of making a website accessible and SEO performant: image alt text. You know, that seemingly small image attribute that describes an image:
<img src="/cute/sloth/image.jpg" alt="A brown baby sloth...
Multiple Background Clip
30.1.2019
You know how you can have multiple backgrounds?
body {
background-image:
url(image-one.jpg),
url(image-two.jpg);
}
That's just background-image. You can set their position too, as you might expect. We'll shorthand it:
body {
background:
url(image-one.jpg) no-repeat top right,
...
Does it mutate?
18.1.2019
This little site by Remy Sharp's makes it clear whether or not a JavaScript method changes the original array (aka mutates) or not.
I was actually bitten by this the other day. I needed the last element from an array, so I remembered .pop() and used it.
const arr = ["doe", "ray", "mee"];
const...
CSS doesn’t suck
15.1.2019
I'm not so protective of CSS that I'm above hearing it criticized, but I'm certainly in agreement here. CSS does not suck. I love how the post is framed to hype up current CSS features the way features of other languages and tools are hyped:
Imagine if a tech dude walked on stage at a conference...