加载中... --°C -- · --% · --
|
加载中... --°C -- · --% · --

What’s !important #10: HTML-in-Canvas, Hex Maps, E-ink Optimization, and More

AI工具
What’s !important #10: HTML-in-Canvas, Hex Maps, E-ink Optimization, and More
摘要

本期内容聚焦多项前端技术实验:HTML-in-Canvas API 可实现带视觉效果的语义HTML渲染;六边形世界地图分析功能结合SVG与CSS,提供设计约束与工程实践回顾;Rekindle为电子墨水设备打造网页操作系统,采用黑白无动画设计并集成大量功能;CSS content属性可替换img标签src,支持image-set()实现响应式图片。

Developers have been experimenting with HTML-in-Canvas, a hexagonal world map-analytics feature, a web-based OS for e-ink devices, replacing img srcs using content, and more. This is What’s !important #10.

HTML-in-Canvas experiments

HTML-in-Canvas, a new API that enables us to render real semantic HTML in a <canvas> with visual effects, is the talk of the town right now, so let’s lead with that. Amit Sheen showed us how the HTML-in-Canvas API works, and also created some demos over at the HiC Showroom, like this one (requires Chrome 146 with the chrome://flags/#canvas-draw-element flag enabled):

CodePen Embed Fallback

Building a hexagonal world map-analytics feature

Ben Schwarz (awesome name, but no relation) talked about building a hexagonal world map-analytics feature. While it’s more of a retrospective than a developer walkthrough, it’s a really interesting read about analytics, design constraints, inspiration, engineering, and of course SVG and CSS.

Source: Calibre.

Rekindle — a web-based OS for e-ink devices

Rekindle is basically a web-based operating system for e-ink devices like Kindle, Kobo, and Boox, which are often low-powered with few features. Rekindle includes an insane number of features and apps, and is designed in black-and-white, with no animations, and no doubt with many more e-ink optimizations.

The takeaway isn’t a tutorial (unfortunately) or even some commentary (like with the world map retrospective above), it’s that we have a whole bunch of media queries that’d be so useful for e-ink devices if it weren’t for the fact that they’re shipping with low-powered, proprietary web browsers that don’t recognize them. Media Queries Level 5 can query hover capability, the precision of pointers, display update frequency, color depth, monochromatic bit-depth, color index size, dynamic range, and more, probably.

Thoughts? Is e-ink optimization likely to break out in the coming years, or is low demand for these media queries why a dedicated service like Rekindle needs to exist? It’s worth noting that the browsers and many of the media queries are in active development, so I don’t know. Watch this space, maybe?

Either way, I’d love to see a dev deep dive on Rekindle!

Replacing img srcs using content

Jon discovered that CSS can be used to replace image sources, like this:

<img src="image.png" alt="Alt text">
img {
  content: url(new-image.png) / "New alt text";
}

TIL! Who knew you could change the "src" of an #HTML <img> using #CSS: img { content: url(whatever.png) } NO PSEUDOS! Seems to work in all current browsers too. How did I miss this?

— Jon (@scrwd.mastodon.social.ap.brid.gy) Apr 20, 2026 at 13:09

It’s really interesting to learn this about the content property, which has been Baseline for 11 years now. I experimented a bit more and discovered that this trick also works with the image-set() function:

img {
  content: image-set(
    url("image.png") 1x,
    url("image-2x.png") 2x
  );
}

So if you’re working on a website with non-responsive <img>s and no way to change the markup, write the logic in CSS instead.

Implementing responsive images with sizes=auto

Having said that, if you do have access to the HTML, you’ll want to serve responsive images using the srcset and sizes HTML attributes. Mat Marquis demonstrated how the new sizes=auto attribute-value combination replaces responsive breakpoints for images that are loaded lazily.

If you’re interested, Amit Sheen also talked about building layouts (not necessarily images) without breakpoints.

New web platform features and updates

If you’re keen for more content, here’s Wes Bos and Scott Tolinski of Syntax.fm discussing 10 new CSS and HTML APIs:

Until next time!


What’s !important #10: HTML-in-Canvas, Hex Maps, E-ink Optimization, and More originally handwritten and published with love on CSS-Tricks. You should really get the newsletter as well.

转载信息
原文: What’s !important #10: HTML-in-Canvas, Hex Maps, E-ink Optimization, and More (2026-05-01T13:43:26)
作者: Daniel Schwarz 分类: 前端
链接: https://css-tricks.com/whats-important-10/ |声明:转载仅供分享;侵权联系删除。
评论 (0)
登录 后发表评论

暂无评论,来留下第一条评论吧