Zero-Width Space

The name zero-width space is antithetical, but it’s not without uses. In text, maybe you’d use it around slashes because you want to be sure the words are treated individually but not have any physical space around the slash:…


The post Zero-Width Space appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

The name zero-width space is antithetical, but it’s not without uses. In text, maybe you’d use it around slashes because you want to be sure the words are treated individually but not have any physical space around the slash:

That’s an image. WordPress was being weird about it and not escaping it even when in a code block.

That’s pretty theoretical though—I’ve never once needed to do that. It might be useful in a long word to suggest that it can be broken there… but that’s also rare as we have the soft-hyphen (­) which is designed for that and leaves a typically appropriate hyphen at the break.

What I have needed to do is exactly the opposite: trick a system into thinking a single word is two words. Like on Twitter, if I @username or #hashtag in the text of a tweet, those will be linked up respectively. But I don’t always want that. On CSS Twitter, I might want to refer to a @media query or show an #id-selector. Toss a zero-width space between the symbols and the text and I’m all set.

Get a zero-width space on your clipboard

Here’s a Pen I created ages ago that will help you do that:

There is also a quick trick for doing it from the browser console:

copy('u{200B}')

via:

And for yet another way that may appeal to you, a bookmarklet!

Copy & Paste concern

The danger with the zero-width space is, well, you can’t see it. If someone were to, for example, copy your @media query using the zero-width space trick from a tweet, it won’t work in their code editor (because it will invalidate the rule) and it might be extremely confusing. For that reason, it’s probably good to avoid using it in anything that might be copied as a code example, but probably fine when explicitly trying to not autolink something.


The post Zero-Width Space appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2021-07-02T20:39:04+00:00) Zero-Width Space. Retrieved from https://www.scien.cx/2021/07/02/zero-width-space/

MLA
" » Zero-Width Space." Chris Coyier | Sciencx - Friday July 2, 2021, https://www.scien.cx/2021/07/02/zero-width-space/
HARVARD
Chris Coyier | Sciencx Friday July 2, 2021 » Zero-Width Space., viewed ,<https://www.scien.cx/2021/07/02/zero-width-space/>
VANCOUVER
Chris Coyier | Sciencx - » Zero-Width Space. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/07/02/zero-width-space/
CHICAGO
" » Zero-Width Space." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2021/07/02/zero-width-space/
IEEE
" » Zero-Width Space." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2021/07/02/zero-width-space/. [Accessed: ]
rf:citation
» Zero-Width Space | Chris Coyier | Sciencx | https://www.scien.cx/2021/07/02/zero-width-space/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.