RSS FeedTwitterMastodonBlueskyShare IconHeart IconGithub IconArrow IconClock IconGUI Challenges IconHome IconNote IconBlog IconCSS IconJS IconHTML IconShows IconOpen Source Software IconSpeaking IconTools IconShuffle IconNext IconPrevious IconCalendar IconCalendar Edit IconNotebook IconObservable Notebooks IconSlash IconGoogle G Icon
A screenshot of some of the code snippets found in this blog post.
A series of images of an avatar doing a bunch of skateboard tricks.4 min read

An Emoji Naming Convention

css

There are many new places in CSS for naming. You can now quickly find yourself using the same name, which is unique, but it's unique in a context… and that's really hard to remember.

Here's a simple example:

@keyframes foo {}
@property --foo {}

.element {
  --foo: bar;
  animation: foo linear both;
  view-timeline-name: --foo;
  view-transition-name: foo;
  anchor-name: --foo;
  container-name: foo;
}

Notice too how there's dashed names and undashed… some CSS features require the dashed names while others do not. Yay.

Good news is that CSS can keep track of it all. Bad news, I'm strugglin.

Not an answer, but an answer? #

I'm not actually trying to tackle this problem with this suggestion, but… maybe I am? LOL

We could, use emoji to help delineate the intended use.

Here, keyframes, typed custom properties and font-palette-values are uniquely identified with an emoji prefix.

@keyframes 🔑-example {}
@property --﹫-example {}
@font-palette-values --🔡-example {}

This then makes it clear when you got to use them:

.element {
  --﹫-example: bar;
  animation: 🔑-example linear both;
}

So building on this, I went a little further… and have assigned emoji's for anything you can custom name:

@keyframes 🔑-example {}
@property --﹫-example {}
@font-palette-values --🔡-example {}

:root {
  --﹫-example-typed: baz;
  --🔒-example-private: foo;
  --regular-var: bar;
}

::view-transition-group(.🏘️-example) {}
::view-transition-new(🏞️-example) {}

@layer 🥞-example {
  .🤓-example-class {
    container-name: 📦-example;
    view-transition-name: 🏞️-example;
    view-transition-class: 🏘️-example;
    view-timeline-name: --📽️-example;
    anchor-name: --⚓-example;
    font-palette: --🔡-example;
    animation: 🔑-example 1s;

    > p {
      @container 📦-example (inline-size < 20ch) {
        font-size: var(--﹫-example);
      }
    }
  }
}

@layer 🥞-example-utilities {
  .🔧-utility-class,  
  .🧹-reset-class,  
  .🔍-debug-class {

  }
  
  .🗣️-sr-only {}
  
  .🍱-grid {}
}

Does this work?!

Yep, perfectly valid CSS. Try it on Codepen.

Did I miss an opportunity to pick an emoji prefix?

Probably! Comment on Bluesky or Mastodon and I'll add them!

As a final mention here, I think it's a good idea to -- all your custom names, just to make it really clear they aren't internal CSS keywords.

13 mentions #

45likes
11reposts
  • Jon Henshaw
  • Lea Rosema
  • Kai Klostermann
  • Jan
  • Roni Laukkarinen
  • Assaf ????
  • Björn Berkholz
  • rol4nd
  • hugo-o
  • Chromium Developers

Join the conversation on

I think we should use emojis in variable names just cuz they're cool ????
TylerTyler
Shouldn’t emojis be later in the variable so we can get them from editor auto-complete rather than having to type them ourselves?
AllanAllan
Emojis are naming hell. One of the things that really bothered me about Scala were some libs that used obscure UTF-8 characters for operators. ????
UnleashedUnleashed
I've been using emoji classes for years codepen.io/thebabydino/...
Ana TudorAna Tudor
god_no.gif
Ivan ČurićIvan Čurić
Makes you think why only some of these have to start with "--" and not others (Well I suppose you know the answer).
SamirSamir
There's a trend I can get behind
Adriana JaraAdriana Jara

@argyleink I have feelings about this.

Kai KlostermannKai Klostermann
but if you type it first, then autocomplete lists just those types but yeah, i hear ya. maybe autocomplete gets good at suggesting emojis with prefixes first and we all win
Adam ArgyleAdam Argyle
It's a cute idea, but in practice probably makes the code less readable for some folks like screenreader users, and less writeable for folks using voice dictation.
Ben Myers ????Ben Myers ????
I'm commenting just to appear in your amazing website!
Emanuel SaramagoEmanuel Saramago
Hungarian Notation with Emoji ????
BramusBramus