TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Show HN: Kerning.js — Take control of your web typography

154 pointsby endtwistover 13 years ago

15 comments

saurikover 13 years ago
This library is misusing vendor prefixes :(... -webkit-* should be an area for WebKit to define custom CSS property, not for this library to tag things "only if using WebKit". If WebKit eventually decides to experiment with a word-color CSS property this is just going to cause problems.<p>Instead, to fit with the standard way people define CSS properties, this library should be taking a prefix for itself, like -kerning-*, and then defining any of its extensions to CSS within that namespace: that way it is almost guaranteed to not cause problems going forward.
paulirishover 13 years ago
Nice work. I like how it all stays declarative in the CSS too.<p>I would recommend outsourcing your parsing though. It's a tough job and things like CSS hacks can really take your regexes for a loop.<p>I'd recommend trying out <a href="http://glazman.org/JSCSSP/" rel="nofollow">http://glazman.org/JSCSSP/</a> or <a href="https://github.com/nzakas/parser-lib/tree/master/src/css" rel="nofollow">https://github.com/nzakas/parser-lib/tree/master/src/css</a> which Nicholas uses for CSSLint.
评论 #3011050 未加载
socraticover 13 years ago
Do people use things like this?<p>I recently read Robert Bringhurst's excellent <i>Elements</i> <i>of</i> <i>Typographic</i> <i>Style</i>, but have no idea how to apply it to the web.<p>(There is an effort to translate the work at webtypography.net, but frankly, most of the sections are some equivalent of "you should do X, but X is not possible right now, but maybe with some CSS extension in the future X will be possible.")<p>It seems like maybe we have choice of fonts now (through TypeKit, Google Web Fonts). But kerning and justification seem to be mostly accomplished through these sorts of JavaScript hacks, and text figures seem outright impossible. What is a wannabe typographer supposed to do on the web with current tools? Are lettering.js, kerning.js, kern.js, linebreak.js and similar usable or just experiments?<p>More generally, what does the current web typographer's toolbox look like at the moment?
评论 #3011580 未加载
评论 #3011733 未加载
评论 #3011332 未加载
Haraldsonover 13 years ago
So, just to get this right; to use this script, you'd have to know your content, right down to how many words each text element contains and so forth? The exception being the pairings and repeats. If you already know your content that well (ie. it's static and not any form of user input), you could just add some extra inline elements to your markup, I mean, you're already heavily customizing the text elements.<p>This is perhaps more elegant, but it makes your CSS too tightly bound to your content. Add a word in the markup, and you'll have to update your CSS as well, with a <i>none</i> or whatnot.<p>By all means, nice work, I just rarely work with pages where I know how the content will turn out.<p><i>Edit: Fixed a typo.</i>
评论 #3011793 未加载
audionerdover 13 years ago
Speaking of kerning, here's a simple CSS declaration for modern browsers:<p><pre><code> text-rendering: optimizeLegibility; </code></pre> ... which will give you improved handling of kerning pairs and ligatures.<p>see: <a href="http://www.aestheticallyloyal.com/public/optimize-legibility/" rel="nofollow">http://www.aestheticallyloyal.com/public/optimize-legibility...</a>
kevingaddover 13 years ago
Completely broken in Firefox, takes ages to load in Chrome. Can't imagine why anyone sane would want to use this library if the cost is so severe.<p>Doing it declaratively through css is nice, but it would be nicer if it used vendor prefixes correctly to avoid namespace collisions instead of misusing them the way it does.
tambourine_manover 13 years ago
What's the performance penalty for wrapping every character in a span? Is it meant for titles only (honest question)?
评论 #3011715 未加载
DieBucheover 13 years ago
So, to style the 235th word in a text, I'd have to do #main { -letter-size: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .... 0.5em; }<p>Why wouldn't I simply wrap it in a span, then it even works on browser with JS switched off. Uh, and once I have to edit the copy and add a single word somewhere, everything breaks.
评论 #3014005 未加载
darylteoover 13 years ago
Does wrapping everything in spans and divs impede SEO in any way?<p>i.e. Google aside, does Bing and other crawlers interpret:<p>&#60;span&#62;Perfect&#60;/span&#62;<p>To be the same as:<p>&#60;span&#62; &#60;span class="word2" style="display: inline-block; "&#62;&#60;span class="char1" style="display: inline-block; margin-right: 1px; "&#62;p&#60;/span&#62;&#60;span class="char2" style="display: inline-block; margin-right: 0px; "&#62;e&#60;/span&#62;&#60;span class="char3" style="display: inline-block; margin-right: 2px; "&#62;r&#60;/span&#62;&#60;span class="char4" style="display: inline-block; margin-right: 0px; "&#62;f&#60;/span&#62;&#60;span class="char5" style="display: inline-block; margin-right: 0px; "&#62;e&#60;/span&#62;&#60;span class="char6" style="display: inline-block; margin-right: 0px; "&#62;c&#60;/span&#62;&#60;span class="char7" style="display: inline-block; margin-right: 0px; "&#62;t&#60;/span&#62;&#60;span class="char8" style="display: inline-block; margin-right: 0px; "&#62;.&#60;/span&#62; &#60;/span&#62;<p>Also...<p>SPANNITY SPANNNN SPANNITY SPANNNN
评论 #3011937 未加载
josscrowcroftover 13 years ago
Great library, great work - kudos to you for tackling a very tricky subject (I'm staying well away from CSS parsing and typography ... for now)<p>My only concern is whether this is (in startup lingo) a painkiller or a vitamin - as in, this is really nice to have, if you're that worried about kerning, but perhaps not enough of a pain-point for designers and developers to warrant learning a new set of nested and prefixed CSS rules, just to do something that's possible to hack together on a case-by-case basis with something like lettering.js...<p>Perhaps if there's a way to simplify the syntax or provide easy copy-paste examples, it'll remove the barrier to entry?<p>Still, applaud the work and the code looks great.
skrebbelover 13 years ago
Not very cross-browser, is it? Even the page itself lays out entirely wrong on Opera.
评论 #3012769 未加载
loup-vaillantover 13 years ago
Apparently doesn't work with no-script, even when allowing the whole page. I suppose there is some cross scripting going on? Or is it because my iceweasel 3.5.16 from Debian-stable is too old?
joelanmanover 13 years ago
While pretty, this really messes up screen readers: as each letter gets wrapped in a span, the letters are read out one at a time.
audionerdover 13 years ago
How does this differ from <a href="http://www.kernjs.com/" rel="nofollow">http://www.kernjs.com/</a> ?
评论 #3011188 未加载
leanover 13 years ago
I'm working on a fine-grained typography control JS library myself, very interesting work.<p>Designers/front-ends, what things would you like to control about your type now, that you can't yet?