Using a CSS cursor to show the external link's favicon


A link with the Google logo hovering over it.

How do you know where this link goes to? If you're on a desktop, you might notice that hovering your mouse over it displays the destination somewhere on your screen. If you're a geek, you could view the source-code of a page. Can we improve the experience for users? Here's an attempt. Try hovering your cursor over this link to a popular website. This is what it should look like: Here's how it works. Cursor Styles CSS allows us to change the icon displayed by a cursor. There are dozens …

Continue reading →

You can use text-wrap: balance; on icons


The HTML5 Logo.

A fun little CSS experiment! There's a new(ish) feature in CSS which allows you to set the way text is wrapped. Ordinarily, a long line of text might be split at an inopportune time. For example: This very long headline ends with a single word Having a dangling word doesn't always look great. Using text-wrap:balance would give us something like: This very long headline ends with balanced lines Hurrah! But the name is, I think, slightly misleading. It doesn't only work on text. It will…

Continue reading →

Styling links based on their destination


The HTML5 Logo.

Suppose you have lots of links on a page. You want to highlight the ones which point to example.com - is that possible in CSS without using JavaScript? Yes! This scrap of code will turn all those links red: a[href^="https://example.com"] { color: red; } Now, there are a few gotchas with this code. It matches the string exactly. So https://example.com will not match https://www.example.com The match will occur at the start of the string. To match more lazily, you can use a substring…

Continue reading →

Inline CSS - The Link "Cheat"


The HTML5 Logo.

I am a bear of very little brains sometimes. I had a site which, for various boring reasons, was printing a <style> element in the middle of the HTML's body. Because <style> is a metadata element, it should only appear within the <head> element. This is OK: <!doctype html> <html> <head> <style> a { color: #f00; } </style> </head> <body> … This is an error: <!doctype html> <html> <head> </head> <body> <style> a { color: #f00; } </style> … Most mo…

Continue reading →

Use CSS to boost the font size of emoji with no extra markup


Group of emoji.

I want to make emoji bigger than the text that surrounds them. At my age and eyesight, it can be difficult to tell the difference between 😃, 😄, and 😊 when they are as small as the text. Is there a way to use CSS to increase the font size of specific characters without having to wrap them in an extra <span> or similar? Yes! Although it is a bit of a hack. This relies on 3 CSS features: src: local(), unicode-range,and size-adjust. Let me walk you through it. @font-face { font-family: &q…

Continue reading →

You can't photocopy this blogpost (abusing EURion in CSS)


The HTML5 Logo.

body:before {position: absolute; content: ''; height:1000px;width:100%;transform: scale(0.5); pointer-events: none; background-image:…

Continue reading →

Using date-based CSS to make old web pages *look* old


Screenshot of an early BBC news website from the 1990s. The page looks old fashioned.

How do you know you're looking at an old website? You may have found a page which has lots of interesting information, but how can you tell it's a modern and relevant result? Some websites don't contain dates in their URls. There may not be a © date or publication date shown on the page. And the <meta> tags might not contain anything useful. If you're lucky, the site will look old fashioned: Unlike the BBC, most sites have adopted the "Eternal CSS" pattern. When fashions change, the entire …

Continue reading →

CSS only colour-scheme selector - no JS required


A light website with a photo of a kitten.

Yesterday I wrote about a lazy way to implement a manual dark mode chooser. Today I'll show you a slightly more sensible way to do it. It just uses CSS, no need for JavaScript. Here's a scrap of HTML which present a dropdown for a user to choose their colour scheme: <select id="colour-mode"> <option value="">Theme Selector</option> <option value="dark">Dark Mode</option> <option value="light">Light and Bright</option> <option value="eink">eInk</option> </select> It will look…

Continue reading →

Laziest Possible Dark-Mode Toggle - Using :has() and invert()


A dark website with a photo of a kitten.

I'm not saying this is a good way to make a dark mode website. I'm not even saying it's a sensible way to do dark mode. But I'm pretty sure this is the laziest way of getting dark mode on your site. And it is all done with less than a handful of CSS rules. It relies on the new-ish :has() CSS pseudo class and the positively ancient filter() CSS function. Here's the code in all its glory: body:has( > #dark-mode-checkbox:checked ) { filter: invert(1); background: #000; } …

Continue reading →

The limits of CSS styling select options


Checkboxes in a line.

Sometimes you learn the most from failures! I wanted a <select multiple> element where the <options> were laid out in a grid. I nearly got there. It's possible to have the <option>s in a horizontal row - but only on Chrome and Firefox. Here's a quick fiddle showing the results: As you can see, it's possible to do some pretty extravagant styling of the individual <options> you can even change how they look when they're selected. But it's impossible to get them to wrap using a flexbox or…

Continue reading →

Responsive Yearly Calendar with Flexbox


A grid of calendars. One calendar item has moved to the next line.

This blog has a calendar showing my yearly archives. It was in a table layout - which made sense when I first designed it - but had a few spacing niggles and was hard to make responsive. Now, it behaves like this: The code is relatively straightforward. The HTML for the calendar looks like this: &lt;div class=&quot;calendars&quot;&gt; &lt;div class=&quot;calendar&quot;&gt; &lt;div class=&quot;calendar-year&quot;&gt;2018&lt;/div&gt; &lt;div…

Continue reading →

How to style your alt text


Photo of a broken and smashed picture frame. Taken by eastbeach on Flickr.

Every day is a school day. I'd recently seen a post about highlighting images without alt text. That got me thinking. Is it possible to style alt text? Yes. Yes it is. And it's pretty simple. Well, OK, it's CSS, so simple is a relative term! Let's take a broken image like <img src="http://example.com/bigfoot.jpg" alt="The best quality photo of bigfoot!" /> There are two slightly different ways to style the text. The simplest way is to give the image some CSS relating to its font, colour,…

Continue reading →