Upper- or lowercase hex codes in CSS?

Published on Monday, October 23rd, 2006

When you write your CSS code, do you use upper- or lowercase hexadecimal codes? I.e., does it look like this: #F2F2F2 or this: #f2f2f2? Personally, I used to go the uppercase route but has now officially switched to lowercase.

What’s your preference?

Posted in CSS, Developing | 69 comments

69 comments

  • trovster
    October 23rd, 2006 at 16:32

    I use either, really. When typing shorthand, I use lowercase. If it is mixed with numbers, (or copied from a program) it tends to be uppercase, and I just leave it…

  • Phil Sherry
    October 23rd, 2006 at 16:34

    Yes: #fff;
    No: #FFFFFF;

  • icaaq
    October 23rd, 2006 at 16:44

    Does it matter?

    i use #fff; anyway.

  • Chris
    October 23rd, 2006 at 16:56

    I absolutely prefer lowercase! Can’t explain :-)

  • James
    October 23rd, 2006 at 16:59

    Lowerase, purely because I’m too lazy to press “shift”.

  • George
    October 23rd, 2006 at 17:02

    Personally I like uppercase. When you are using CSS shorthand it helps the colour stand out:

    background: #FF0000 URL(/images/backgrounds/tickets.jpg) 5px 5px no-repeat;

    I wouldn’t mind going lowercase though - I don’t think it really matters does it?

  • Martin S.
    October 23rd, 2006 at 17:07

    I try to use lowercase just to be consistent in my coding. Since I use XHTML and it requires elements, attributes and so on written in lowercase I try to apply it to other front end coding too.

    However, the hex codes in Photoshop are in uppercase and I just copy and paste them sometimes when time is a very important factor.

    And when possible, I use shorthand hex. :)

    Robert: why are you now writing your hex codes in lowercase?

  • Jens
    October 23rd, 2006 at 17:20

    Always lowercase.

  • FlorentG
    October 23rd, 2006 at 17:27

    I use lowercase everywhere, so I can shave a few bytes when your CSS is gzipped

  • Johan
    October 23rd, 2006 at 17:36

    I think it is fashion!

  • Goulven
    October 23rd, 2006 at 17:56

    Always lowercase, because B looks a lot like 8. Not so with b.

    As an aside, this saves me from pressing shift, for what that’s worth.

    Glad you asked ! :-)

  • Steve Williams
    October 23rd, 2006 at 18:04

    When I type it’s always lowercase and short form if I can, but when pasting from photoshop it uses all caps - sometimes I leave them alone, but usually end up hand editing ‘cos they get on my nerves… How anal am I ? :)

  • Kevin
    October 23rd, 2006 at 18:13

    Lowercase. As Goulven pointed out it increases readibility (to me anyway).
    And Steve: you’re not the only one ;)

  • Árni Gunnar
    October 23rd, 2006 at 18:15

    Uppercase all the way … and shorthand when I can :)

  • Björn Thomasson
    October 23rd, 2006 at 18:36

    Always lowercase (even if I have to hand edit from Photoshop) - for no other reason than that it looks appropriate (from using XHTML code probably)…

  • Harmen Janssen
    October 23rd, 2006 at 18:41

    Always lowercase. Not sure why, it just feels good :)

  • Harmen Janssen
    October 23rd, 2006 at 18:42

    Always lowercase. Not sure why, it just feels good :)

  • Robert dM
    October 23rd, 2006 at 18:51

    always uppercase since hexadecimal codes where always written in uppercase when I first learned about them (before I got into webdesign), haven’t seen them used in lowercase outside weddesign much. Makes them easier to recognize as hexadecimal codes.

  • Johan
    October 23rd, 2006 at 19:28

    Uppercase does make one think too much of the time when we used FONT TAGS.

    We thought the Web was big and now we are happy with lowercase and highband-width!

  • Tanny O’Haley
    October 23rd, 2006 at 19:39

    When I type them I always use lowercase. Must be because I had programmed in C for so long. However, when pasting from Photoshop or Eric Meyer’s Color Blender most of the time I leave them as they are which is uppercase.

  • Devon
    October 23rd, 2006 at 19:44

    Uppercase. Why? partially habit, and partially because it helps it stand out better when I glance through the code.

  • Roger Johansson
    October 23rd, 2006 at 19:46

    Lowercase. And I find it very annoying that Photoshop uses uppercase since that prevents me from copying colour codes from it.

  • Jonathan Snook
    October 23rd, 2006 at 19:47

    I do uppercase because of the aesthetics. I like it to be all the same size. #eb120f looks messy but #EB120F looks hot. :)

  • Reine
    October 23rd, 2006 at 19:55

    Lowercase, while having the same issue with Photoshop as the other commenters.

  • Sean Fraser
    October 23rd, 2006 at 20:36

    Lowercase. I like the aesthetics. And, something to do with well-formedness written in all lowercase, I got into a habit. And, Yes; I’ll rewrite Photoshop Hex.

  • eruntale
    October 23rd, 2006 at 20:36

    uppercase, most of the times, it helps differencing colors from CSS code (i think :))

  • Robin
    October 23rd, 2006 at 20:45

    All lower, all the time. I even end up editing the uppercase letter my colleagues’ Dreamweavers add, which thinking about it is probably quite sad.

  • Eugene
    October 23rd, 2006 at 21:45

    shorthand: lowercase, else uppercase.

  • Phil Thompson
    October 23rd, 2006 at 21:46

    UPPERCASE; because I just prefer how it looks. Also because Photoshop and Colorzilla product uppercase hex codes.

    I also try to go shorthand e.g. #FFF instead of #FFFFFF where possible.

  • Martin Jansson
    October 23rd, 2006 at 22:17

    I use lowercase… and I think it’s because almost everything else in the CSS is written in lowercase, except maybe some camelCased id’s or something.

  • Robert Nyman - author
    October 23rd, 2006 at 22:30

    Thanks for sharing, everyone! Interesting to hear about your woes with Photoshop. The reason I actually started with lowercase is that in Photoshop CS 2, the hex codes are in lowercase! :-)

    Once started, I liked the readability of it; I also agree with Martin’s motivation above that everything else in the CSS is (usually) lowercase so it feels more consistent.

  • Nathan Smith
    October 23rd, 2006 at 22:44

    Shorthand and lowercase, all the way. woot.

  • Björn Thomasson
    October 23rd, 2006 at 23:37

    Robert, you are right - CS2 is lower case and no need for editing! I hadn´t even noticed that och was ranting about passed sins…

  • Thomas Higginbotham
    October 24th, 2006 at 0:51

    Definitely lowercase. Using uppercase reminds me of the old days when HTML tags were written in uppercase to help distinguish them.

    Lowercase just has the “modern” edge to it.

  • Karl
    October 24th, 2006 at 1:07

    Lowercase, purely because it’s one less key stroke (shift). I have set ColorZilla up to match when picking colours but there’s no science to my choice.

  • Lachlan Hunt
    October 24th, 2006 at 4:14

    OMG! I’m very surprised to see so many people prefer lowercase! And I can’t believe some of you use either and have them mixed throughout your code. What on earth is wrong with you? You’re all crazy!

    Uppercase is more asthetically pleasing and it’s how hexadecimal is supposed to be written. I use uppercase for all hex for colours (#FFF) and escape sequences (\A0 ) in CSS, character references in HTML ( ), and also Unicode code points (U+00A0). I never ever use lowercase and I don’t like Photoshop CS2 because it does lowercase and I have to change it when I copy and paste.

  • Kanashii
    October 24th, 2006 at 5:20

    I use lower-case throughout my CSS and id/name attributes in HTML. I can understand Lachlan’s point on hexadecimal though, and being consistent is important. One or the other, got to be neat.

    Lachlan: Why the upper-case for named character entities? They’re not hexadecimal :)

  • Lachlan Hunt
    October 24th, 2006 at 5:59

    Kanashii, I didn’t say “named character entities”, I said character references. They are different things.

      is an entity reference, &#160 is a numeric character reference and &#xA0 is a hexadecimal character reference. Besides, entity references are case sensitive, so you can’t choose upper or lower case when you use them, and most (not all) are defined using lowercase.

  • Kanashii
    October 24th, 2006 at 6:22

    Lachlan: Sorry, I misunderstood. Brain not working to well for me today..

  • Tommy Olsson
    October 24th, 2006 at 7:24

    Lowercase. And I never use six digits if three will do; i.e., #369, not #336699.

  • Siegfried
    October 24th, 2006 at 8:56

    Hi,
    i’m neither using upper- nor lower case. I’m only using decimal notation in CSS. And luckily in decimal digits there is no such question.

  • Robert Nyman - author
    October 24th, 2006 at 8:58

    Again, thanks for sharing. I forgot to say that I also, of course, use shorthand (three characters instead of six) when possible. I’ve even heard of people using only colors that can be shortened to three characters, but that’s stretching it a bit far, if you ask me… :-)

  • Jens Wedin
    October 24th, 2006 at 9:30

    lowercase as I think it goes quicker to type it. It also looks soo much nicer *smile *. I usually mix when coding CSS and copying and pasting from PS or FW, when done I use the “Convert to lowercase” in DW.

  • Rob Kirton
    October 24th, 2006 at 9:54

    I have long since harboured the belief that most developers are obsessive and to some extent their behaviour traits can be assigned to be somewhere in the autistic spectrum. Not really as scary as it sounds, but food for thought. The comments here certainly don’t persuade me otherwise. Think about the ritualistic behaviour and the need to order (i.e. make consistent) when it has no real effect on the outcome.

    P.S. lowercase :0)

  • Phil Sherry
    October 24th, 2006 at 12:33

    Roger: “And I find it very annoying that Photoshop uses uppercase since that prevents me from copying colour codes from it.”

    I find this with DigitalColor Meter as well, but the solution is easy: Highlight in TextMate, right-click, convert > lowercase.

  • Teddy
    October 24th, 2006 at 12:48

    When it comes to programming, web development, file/folder naming and so on I always tend to go with lowercase all the way.

  • Robert Nyman - author
    October 24th, 2006 at 20:31

    Comment bonanza here! Thanks for your comments.

    Rob,

    It is definitely food for thought, and I know exactly what you mean. :-)

  • Jens Meiert
    October 25th, 2006 at 0:16

    Lowercase, for a few months now, and tied in all new coding guidelines I can put my hands on (except the one just referenced… ;)).

    By the way, you’ll certainly forgive me when I diplomatically note the fresh “World’s Highest Website” here, which basically shows up “some CSS challenges”.

  • Rowan Lewis
    October 25th, 2006 at 1:38

    Lowercase because its easier to distinguish between lowercase letters and numbers than it is uppercase letters. However, I’m sure this is the 100th time someone has said as such!

  • Rowan Lewis
    October 25th, 2006 at 1:41

    Oh, forgot to say, I never use the shortened three digit colour code because I often tweak with colours its easier to just INS + new character rather than have to fill out all the missing three :)

  • Robert Nyman - author
    October 25th, 2006 at 9:01

    Jens,

    Thanks for the link.

    Rowan,

    Yeah, I see what you mean with tweaking and designing and choosing colors directly in the CSS.

  • Robert Wellock
    October 25th, 2006 at 12:07

    I also decided to go lowercase on CSS a few years back even though it’s not necessary and unconventional for hex.

  • MichaÅ‚ StempieÅ„
    October 25th, 2006 at 13:08

    Lowercase, short (where possible)

  • Billytheradponi
    October 25th, 2006 at 15:19

    Uppercase with all 6 letters:

    #FFFFFF, not #FFF or #fff or #ffffff, just #FFFFFF

  • Robert Nyman - author
    October 25th, 2006 at 22:09

    Robert W, Michał, Billytheradponi,

    Thanks for sharing!

  • Fredrik Norlin
    October 26th, 2006 at 1:15

    I use lowercase and shorthand when possible.

    I first read this post yesterday. While I was reading the comments I began to wonder which one is most correct. My first thought was that the shorthand notation is illogic, since A isn’t the same value as AA. The value of A should be 0A if it’s hexadecimal. Now I just had to find a standard telling me whether upper- or lowercase representation of A-F should be used and my quest would be over. But I couldn’t find any.

    Today another thought came to my mind. What’s best for the page visitor? I began to calculate the cpu cost of the conversion from the string value read by the browser, to a rgb datatype value used to for the actual output on the screen. I figure the shorthand conversion cost more than converting from a six character hexadecimal value. Using the rgb functional notation should be the fastest color value to convert.

    Anyway - I guess no one use enough colors to make a notable difference and using the rgb functional notation would make the style sheet a few extra bytes per color… I’ll stick to lowercase and shorthand for a while.

    Much ado about nothing - sorry for wasting your time ;-)

  • Robert Nyman - author
    October 26th, 2006 at 10:21

    Fredrik,

    Interesting thoughts! Like you say, not sure anyone notices a difference, but I like your thinking! :-)

    Pat,

    Maybe… :-)

  • neojp
    October 26th, 2006 at 19:42

    When I’m writing colors for CSS I use uppercase letters: #FF0000.

    But when it comes to black, white, gray, or other colors that have the same letter, I just use 3 uppercase letter: #FFF, #CCC. Oh yes, and numbers too: #000, #666.

  • Azad
    October 27th, 2006 at 21:04

    Always UPPERCASE. So that the hex is easily distinguishable from the rest of the CSS mess.

  • Robert Nyman - author
    October 27th, 2006 at 22:16

    neojp, Azad,

    Thanks for your comments.

  • Müfit Kiper
    October 28th, 2006 at 0:42

    For the sake of diplomacy I always change UPPER/lower every other:
    #FfFfFf :)

  • Chad Bishop
    October 29th, 2006 at 0:52

    I’m with you. I used to exclusively do upper case, and now have officially switched to lower.

    Probably made sense at the time to not have to hit Shift or Caps-Lock!

    -cb

  • Robert Nyman - author
    October 29th, 2006 at 13:13

    Müfit,

    Ha ha! :-)

    Chad,

    Welcome to the lowercase crowd. :-)

  • Niklas
    October 29th, 2006 at 21:52

    And I thought I was the only one thinking about stuff like this…
    Recently switched to lowercase!

  • Bel-Air
    October 30th, 2006 at 2:27

    I use the lowercase because simply it makes the flow of typing the CSS to be easier then making changes to the way that I type everything else. I type all of the selectors and others in lowercase so I stick with the same thing when it comes to the hex colors.

  • Robert Nyman - author
    October 30th, 2006 at 9:42

    Niklas. Bel-Air,

    Thanks for sharing!

  • Rudy Johnson
    November 8th, 2006 at 22:38

    Uppercase:
    - shorthand always
    - stands out for some reason in CSS files
    - habit

    Lowercase
    - shorthand always
    - habit from writing for XHTML

    I have been caught doing both … would not spend too much time thinking about it either way until someone tells it actually matters … css4 maybe? ;)

    Content Heavy Web Development

  • Robert Nyman - author
    November 9th, 2006 at 9:50

    Rudy,

    Thanks for sharing.

  • TheMystical
    May 17th, 2007 at 19:44

    What’s CSS in the first place???

    Ah ah j/k.

    Same as Rudy BTW.

Share your thoughts:

HTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> . If you want to display code examples, please remember to write &lt; for < and &gt; for >.

Comment preview

Top results