Reader Kartlos emailed me in pointing to me to an interesting article by the great Mr. Snook from a few years back. I don’t think I had seen it before and it’s a bonafide “CSS Trick” so I thought I would share.
The idea is that you can use unicode characters (read: fancy symbols) for class names in your HTML, and even use write CSS selectors with those same characters.
<div class="♫">
A.A. Bondy
<em>I Can See The Pines Are Dancing</em>
</div>
.♫ {
display: block;
background: #eee;
padding: 5px;
}
Pretty cool eh? I’d call my example above perfectly semantic as well, since the div with the music note class name is marking up a musician and song. Possibly even more semantic, as a music note symbolizes music moreso than any English word.
I put together a super simple demo page that shows it working. Oh, and yes-it-works-in-IE6™ & yes-it-validates™
But…
One funny thing? View the source on that page. I use PHP includes for the headers and footers of all my demos, and because of the character encoding (?) of that page the PHP doesn’t run it just sits there as text.
That ain’t right.
Coda does warn you first.
Weird eh? If you know how this could work both ways, let me know.
Other uses
Jonathan presented (in his original article) and idea for targeting the corners of a box.
<div class="□">
<div class="┌">
<div class="┐">
<div class="└">
<div class="┘">
content
</div>
</div>
</div>
</div>
Remember back a few years ago most of us were rocking rounded corners with nested divs and images like that! The corners symbols are clever, but I could see the <div class="□"> being used for like “container” or “box” style classes today, or, perhaps best of all, the clearfix.
I posted a little code clip of this over on Forrst (sorry I know most folks don’t have accounts there yet) and a guy named Aaron had a funny idea. Using upside down writing to be annoying! id='ɹǝpɐǝɥ', id='ɹǝddɐɹʍ', id='ɹǝʇooɟ'
This is funny!
Very interesting and a quite semantic-way for using Class-names.
Chris, this is a real neat trick. Though every programming bone in my body is screaming “don’t use this in production” hehe.
One thing about the php, I don’t see any tags in the source of the demo page – http://pastebin.com/1hG0Xdzu
Cool idea! I don’t see any problem with PHP tags though, and I’m always using UTF-8.
For example:
http://hatboats.se/unicode/
http://hatboats.se/unicode/index.phps
haha awesome! I might try it and use a heart for my link love section on my blog lol
Interesting, definately like the idea of using ‘□’ for containers.
Arrows, ⇇ could work for floats, ⅓, ⅔ etc could be useful for grids too
Using ⇇ for a float is akin to using “floatleft” as a classname…
That is very cool, I like the corner of the box approach. Wonder if the likes of Tim Berners-Lee had that in mind when he was talking about the semantic web – musical notes for DRM encrypted files.
As a programmer involved in the Semantic Web for some time, I can fairly confidently say that UTF-8 class names – though cool – aren’t exactly what timbl means by the Semantic Web.
Would be cool to use ♠ ♣ ♥ ♦ on a casino/online betting site. Just gotta find someone who wants one!
though probably something that i would not use everyday this just made my day. too funny, i really would never have even thought to consider using any of those characters.
some things are down right sad, and others just across the line are down right cool!
not sure where this lies yet lol
Chris,
So, you should use ⋆ for your main class.
Like it.
check out some stars…. (⋆)
http://www.fileformat.info/info/unicode/char/search.htm?q=star&preview=entity
I think everyone should always use UTF-8. There are much more advantages to it, than using for example ISO-8859-1.
I ♥ it. It’s exciting how all comms r now getting more symbolic than alphabetic.
haha…this IS funny…and pretty cool
Thanks Chris, for a fun article to distract me from the brain dissolving code I’ve been staring at for the past 6 hours! ; )
This is really cool. Never even crossed my mind that you could do something like this? Are there any issues at all apart from the warning?
The box idea is really interesting and could be highly useful, I get fed up of forgetting what I have named certain classes etc and relating it too a symbol would be much easier to remember.
Plus the fact that it will make your stylesheet look pretty funky!
Might start giving it a go see what the reactions are too it!
This is such a neat trick! And strangely enough, I completely agree on the semantic nature of the note symbol in place of “music”. I’d love to see someone sneak that into their markup.
Also, here’s a Forrst invite code good for 25 signups, just for you guys: tricky (use it at forrst.com/signup)
This could sure be a lot of fun to use. Thanks for the tip and also, thanks @Kyle for the Forrst invite code!!
This is cute!
here you have a Unicode map
http://www.atm.ox.ac.uk/user/iwi/charmap.html
Please don’t ever do this, everyone. Please.
How about some details on why? I clearly had my own problems with it, in regards to PHP, but are there others?
Roger, you’re right. It isn’t really practical or semantic, just kinda fun. I don’t agree that the ♫ is a more semantic way to mark up artists and song titles. If you were actually marking up a musical score maybe (somehow?), but not the labels used to identify musical pieces.
What about the section symbol § though? Would that be an appropriate alternative to the word section?
Excellent post Chris. I like using the □ idea, and will probably start doing it for clears.
But isn’t this akin to including presentational class names? Doesn’t seem very semantic…
The traditional argument is that a class name like “left” is non-semantic because it’s presentational. That thing that it wraps may not always be on the “left” side. A better name would be “sidebar”, because that may better describe the content inside it.
A music note as a class name for a div wrapping information about music seems awesomely semantic to me. What is “presentational” about that?
Hm, I guess I was thinking that the music note is more of a visual symbol than an actual description.
(I actually love this idea, I just feel there’s something a little off about it.)
“sidebar” is only marginally more semantic than “left”. Sidebar still implies position and visual interpretation of content, rather than actual content. “sidebar” tells me nothing about what is IN that element, it tells me what it should be.
A music note as a class name for a div wrapping information about music is certainly semantic in spirit, however to a code editor it is entirely inaccessible. It relies on interpretation of the symbol, intellectually and potentially audibly if someone has sight problems.
You’re developing sites semantically for accessibility, and then make the delicious irony that the editing and reading of your code itself isn’t accessible to all? It’s creative but practically just seems ridiculous, even on the base level of how the hell someone finds that character on their keyboard without using copy and paste.
pretty neat… but that php bug can cause some serious security issues don’t you think?
Chris – I just tried entering that symbol into Coda and had no problem at all. I used the Edit > Special Characters menu item to insert it– but I do have Coda set to use UTF-8 encoding….
How is this a trick? We europeans have been using UTF-8 strings for years. Symbols are original, but UTF-8 strings such as “class=’entête'” are pretty common.
Cool trick. I use symbols like !?+~ for short, special classnames, like the pipe character (“|”) for vertical dividers. Then I escape the character in CSS (“.\|”). Works fine in Javascript too, and in jQuery (but not Dojo unfortunately).
lol, what the hack class=”⧻ഞﶈ”
Does anyone know if this can be used for id’s as well as class names?
Chris – can’t wait until you come back and have to modify some code you’ve written using this “trick” six months from now… you’re going to hate yourself when you try and remember the keystrokes for ♫ as opposed to ♣.
That being said, the PHP executables don’t support UTF-16. Save your source document as UTF-8 and you should be fine. If you examine the source for your demo, although you’ve set the meta header to UTF-8, the document itself is still actually in UTF-16.
I’m with Blake. Part of the engineering tradeoff in writing code is maintainability. Non-textual names are cute and novel, but it’s not clear to me they are better.
One of my software engineering teachers claimed that source code (and this would apply to CSS also) is a medium for the original developer to communicate with all the future maintainers of the code, and that the behaviour of the computer on executing the code was a side effect.
Using FF3.6 and view source shows the php calls, rather than running them, like you said.
Nice find by the way. A fun way to spice up your classnames :B
funny, cool, awkward.. all at the same time.. and we’re talking css. we must be nerds ;)
I’m sorry, but I don’t think this is semantic at all. I would actually say that it’s less semantic than words in this case.
The note symbol could for some people represent actual notes (this is what I myself couple with a note symbol), music in general or simply sound.
I don’t think semantics and abstract is such a good combination. This is for example why I guess you’ve written “Articles” next to you news paper icon in the menu.
Hey Chris thanks for mentioning me in the article.
For valid XHTML character entity reference I would recommend everyone this site: http://www.digitalmediaminute.com/reference/entity/
Really interesting thing; I’ve seen all over the net some subdomains named with a character also =)
Leave it to you, Chris, to think outside the box like this. Nice.
I don’t see it as semantical at all. A pair of eighth notes can represent so many things. An artist name? A song? An artist name and a song? An album? A rhythm? If you have to look at the context it is being used in to find its meaning, it isn’t semantic.
If the □ can mean a box, container, or a clear fix, then it isn’t semantic.
The problem with using pictures for semantics is they can be interpreted differently by other people. Seeing a □ isn’t going to provide anyone, but the page creator, any information. They have to look at the elements around it to get an idea of what that class is supposed to do. Contrast that with a class name of clearfix – you know without a shadow of a doubt that that class is a clearfix.
Cool? Yes. Semantic? No.
I disagree again here. I think “clearfix” is incredibly non-semantic. How does that help describe the content it contains? It absolutely doesn’t, it’s purely a presentational fix. Describing without specifying is what I think semantics is all about.
But you haven’t described anything. You’ve used a picture that means something to you and you alone. How is that semantic?
Because a music note is a symbolic representation of music and symbolic representation = semantics. I am not the only person on Earth that knows that, so it’s not “me and me alone”. If I had two pocket folders on my desk, one of them had a cross on it and the other one had a music note on it, which one do think I’d keep my sheet music in?
You’re making the assumption that I know you keep sheet music in a folder labeled with a pair of eighth notes.
I know nothing about you. If I were to look at your desk and see two folders, one labeled with a cross and one labeled with a pair of eighth notes, I would start making assumptions about your faith and your musical background. The folder with a cross could contain scripture, sermon transcripts, pictures of fellow church-goers, church bulletins from the year 2000. I can look around your office/room, and try to discern exactly what the folder contains, but I know nothing of that folder until I look inside it and see what exactly you keep in a folder labeled with a cross. It’s clear to you because you know exactly what is in the folder. To me it’s a folder with a picture on it, and I have to look at contextual clues or look in the folder to find out exactly what the folder contains.
I agree that musical notation is a universal representation of music, but a pair of eighth notes tells me nothing of what you keep in the folder labeled with the notes. It could be sheet music, it could be papers that you have to grade from a theory class, it could be lyrics to songs you like, or it could contain a detailed list of the CDs, cassettes, and MP3s you own. I don’t know what it contains until I look inside it. Generically, yes, I know it pertains something to music, but that’s all I know from looking at the picture. If the picture was semantical, I would have no trouble discerning the exact contents of the folder.
You make the assumption that someone knows what a picture means to you. In doing so, you make the reader/maintainer have to assume the contents by looking at contextual clues or by looking at the contents of the container.
I think Jeremy has a really good point here -about the symbols anyway- but I feel like most of you guys are completely missing the point of unicode class names.
The unicode character set doesn’t just contain cool symbols; unicode is multilingual.
<div class="コンテナ">
might be easier to read for a Japanese designer/developer in terms of semantics.Also, what oakleafs said :p
sounds like fun.
…how did you do the upside-down-writing? :-)
i know a website where you can enter a text and get it back flipped, but how to do it yourself?
Actually, the corners idea is pretty clever! I believe we are going to use that from now one!
I love the corners idea, just emailed the link to six people! hahaha I can’t believe how cool it will look ;)
Thanks for that one, can’t stop giggling about how great the trick is!
Cheers!
Mr.Crazy Chimp
This is coool! I love this idea. Does it work for all browsers?
It’s nice, but i was confused to find these characters more…
This is quite cool. But as @Ronald has also said, does it support all the major browsers?
so awesome
This is fun and unusual, but I think it is useless.
This is funny, but IMHO an “icon” is not really semantyc.
well yes, a note symbol is more semantic, if you’ve completely insane. actually (seriously) a note symbol is loosely associated with anything related to music. thus song-lyrics or song-title are much better class names than a utf symbol for a note. maybe using a note symbol was a horrible example of a generally good idea. but maybe it’s akin to a html/css editor that uses syntax coloring as well as coloring all the hex color codes. a bit over the top for me.
btw the horrid box css should hopefully disappear one day, to be replaced by something that does more presentatonal things like svg. sorry chris–i’m not insane and talking to myself–the box/note should be replaced by utf for a great white elephant. good to stimulate such discussion though.
I had no idea this was possible! Thanks Chris.
While we’re on the subject of semantic class names, isn’t it funny that there is a head, body and footer of a document and yet we don’t call a sidebar a “right-arm” or “left-arm”?
We’re leaving out a whole bunch of body parts as a matter of fact. ha!
seems we’re back to kindergarden!
don’t get me wrong, I like the idea. also a great way to make your sitebuild frustrating to the coder, and vice verse, not to mention the multis employing a broad range of nationalities, the different natural write symbols can get frustrating as well =]
so, it would be funny to use chinese names and symbols…
c’mon, get serious!
I can see using this for compressing extremely large style sheets where multiple class names are used per element.
You could go all semantic in dev and then run your code through a minimizing script to just replace class names before pushing it live.
Well, where would the internet be without unicode selectors.
When this looks interesting, I wouldn’t recommend/use it. Class names as well as ID’s play a role in SEO, so better pick them wisely.
What a fun idea. If you want a snazzy javascript app for browsing Unicode characters, try the Unicode Character Finder