首页›Lea Verou›文章

Awesomplete: 2KB autocomplete with zero dependencies

Lea Verou · 2015年2月19日

AI 摘要 AI 生成,可能有误

由于 HTML5 元素在各浏览器中表现不一致且缺乏可定制性,加上现有的自动补全脚本过于臃肿且往往依赖 jQuery,作者因此自己编写了一个名为 Awesomplete 的小部件。这个小部件极其轻量——压缩并 gzip 后不到 1.5KB——且零依赖,可在 IE9(勉强支持)、IE10+、Chrome、Firefox、Safari 5+ 以及 Mobile Safari 中运行。它已在 GitHub 上发布并附有文档;虽然开箱即用未必能满足复杂需求,但它的设计便于修改和扩展。

awesompleteSorry for the lack of posts for the past 7 (!) months, I’ve been super busy working on my book, which up to a certain point, I couldn’t even imagine finishing, but I’m finally there! I’ve basically tried to cram all the CSS wisdom I’ve accumulated over the years in it :P (which is partly why it took so long, I kept remembering more things that just *had* to be in it. Its page count on the O’Reilly website had to be updated 3 times, from 250 to 300 to 350 and it looks like the final is gonna be closer to 400 pages) and it’s gonna be super awesome (preorder here!) :D . I have been posting a few CSS tricks now and then on my twitter account, but haven’t found any time to write a proper blog post.

Anyhow, despite being super busy with MIT (which btw is amazing, challenging in a good way, and full of fantastic people. So glad to be here!) and the book, I recently needed an autocomplete widget for something. Surprisingly, I don’t think I ever had needed to choose one in the past. I’ve worked with apps that had it, but in those cases it was already there.

At first, I didn’t fret. Finally, a chance to use the HTML5 <datalist>, so exciting! However, the more I played with it, the more my excitement was dying a slow death, taking my open web standards dreams and hopes along with it. Not only it’s incredibly inconsistent across browsers (e.g. Chrome matches only from the start, Firefox anywhere!), it’s also not hackable or customizable in any way. Not even if I got my hands dirty and used proprietary CSS, I still couldn’t do anything as simple as changing how the matching happens, styling the dropdown or highlighting the matching text!

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Lea Verou

Nudeps: bundler-like imports, none of the baggage

AI 摘要Nudeps is a lightweight build tool that lets developers keep using npm install and import dependencies by bare specifiers (like "vue") directly in the browser, without a bundler. It works by copying dependency files from node_modules into a deployable client_modules directory and generating an import map (using JSPM under the hood), touching only dependencies and never the developer's own code, so it requires no watcher and complements any other tooling. It supports many edge cases like dynamic imports, git dependencies, and CJS packages via a require() shim, but doesn't transform code (TypeScript/JSX still need their own tools), is npm-only for now, and may load many-small-module packages more slowly since it doesn't bundle.

Candidate Statement for the 2026 W3C TAG Election

AI 摘要In her candidate statement for the 2026 W3C TAG election, Lea Verou announces she is running to return to the TAG after serving two terms (2021–2025), with her participation this time fully funded by Google, Microsoft, and the OpenJS Foundation. She highlights her broad web platform experience and past TAG contributions, including the Web Platform Design Principles, API design reviews, and the Web Platform Gaps initiative. Her central platform is for the TAG to proactively shape the Web's architecture rather than just review it, including treating the rise of AI agents that write and consume web code as an architecture question guided by principles and evidence.

The best way to use icons in Web UIs

AI 摘要The article argues that the dominant ways of adding icons to web UIs—inline SVG markup and icon fonts—are clunky, boilerplate-heavy, or riddled with problems like large downloads and accessibility issues. The author proposes a pure CSS system where icons are design tokens defined as custom properties (e.g., --icon-trash) and rendered via pseudo-elements using CSS masks, so icons automatically follow text color, can be assigned per-component (e.g., a .delete button gets a trash icon by default), and can reactively change based on selectors, states, or media queries without touching markup. This approach keeps simple cases easy, complex overrides possible, and avoids usability cliffs, with the only remaining need for inline SVG being cases that require dynamically morphing the SVG itself.

The best dark mode toggle is probably none

AI 摘要In this follow-up to her earlier article, the author argues that the best dark mode toggle is no toggle at all, though if one is required, a two-state control alternating between system and the opposite theme beats a tri-state (system/light/dark) one. She rebuts Bramus's objections—such as the OS auto-switching edge case—contending that the failure scenario is rare and cheaply recoverable, that polls of developers measure preference rather than usability, and that tri-state controls add unnecessary cognitive load by exposing the implementation model instead of the user's actual goal. The piece also recounts the widespread positive reception of the original article and the alternative designs the ensuing debate inspired.

Dark mode toggles: two states are enough

AI 摘要The article argues that tri-state dark mode toggles (Light/Dark/System) leak the underlying data model into the UI and solve a largely imaginary user goal, since real users only seek out the toggle when something looks wrong. It advocates a well-designed two-state toggle that shows the currently resolved value and alternates between storing an explicit override and reverting to the system default, capable of expressing all three underlying states. Key implementation rules include only evaluating the stored override at user interaction, keeping it even if the OS preference later coincides with it, since any resulting confusion is rare and fixable with a single click.