According to EmacsWiki there are bunch of CSS modes for Emacs, but none of them seems to be very actively developed or even that feature complete. Which one is the most feature complete so far and is being maybe even maintained?


  • Syntax highlighting
  • Well behaved indentation
  • Commenting
    • Region
    • Line
  • Validation
    • Error reporting

Problems with the default CSS mode

One of the reason why the current CSS mode doesn't cut it for me is because it indents selectors NOT like this

div.bar input,
div.bar select {
    float: left;

, but like this

div.bar input,
        div.bar select {
                float: left;

which is simply unbearable.

3 Answers 3


I'm using the css-mode that comes with GNU Emacs 24 and it indents fine (the way you want). It does all what you want except validation, and it's part of GNU Emacs so it's maintained. I haven't tried it, but I think css-tidy.el can do validation.

The only customizations I have are

(setq cssm-indent-function #'cssm-c-style-indenter)
(setq cssm-indent-level 2)

but I think those are remnants of some former css mode since neither is defined anywhere. What Emacs are you using and what command is being used to indent (C-h k TAB)?

  • 1
    I'm using the Emacs 23.3. (9.0) on Mac OS X which I installed with homebrew. It might be that I ought to update the CSS mode from the upstream. Someone else told me about those customizations as well, but they don't seem to work.
    – Bleadof
    Jan 31, 2012 at 12:18
  • It looks like neither css-indent-function nor css-indent-calculate has changed since 2007 when the file was initially imported. It seems like something must be messed up. What is the value of indent-line-function? Jan 31, 2012 at 18:10

if you are doing inline where you have both html and css code look into nxhtml mode, its one mode that will have the proper syntax editing and highlighting for both css and html.

  • Sadly that's not what I'm looking for...
    – Bleadof
    Mar 6, 2012 at 15:08

If you're using Spacemacs (develop), you need to add this to your (defun dotspacemacs/user-config ():

(setq-default css-indent-offset 2)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.