Hanging punctuation in CSS
There’s a lovely CSS property called hanging-punctuation
. You can use it to do exactly what the name suggests and exdent punctuation marks such as opening quotes.
Here’s one way to apply it:
html {
hanging-punctuation: first last;
}
Any punctuation marks at the beginning or end of a line will now hang over the edge, leaving you with nice clean blocks of text; no ragged edges.
Right now it’s only supported in Safari but there’s no reason not to use it. It’s a perfect example of progressive enhancement. One line of CSS to tidy things up for the browsers that support it and leave things exactly as they are for the browsers that don’t.
But when I used this over on The Session I noticed an unintended side-effect. Because I’m applying the property globally, it’s also acting on form fields. If the text inside a form field starts with a quotation mark or some other piece of punctuation, it’s shunted off to the side and hidden.
Here’s the fix I used:
input, textarea {
hanging-punctuation: none;
}
It’s a small little gotcha but I figured I’d share it in case it helps someone else out.