Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:26:53+00:00 2026-05-24T16:26:53+00:00

I was having a look at the CSS syntax here and here and I

  • 0

I was having a look at the CSS syntax here and here and I was amazed to see both the token productions and the grammar littered with whitespace declarations. Normally whitespace is defined once in the lexer and skipped, never to be seen again. Ditto comments.

I imagine the orientation towards user-agents rather than true compilers is part of the motivation here, and also the requirement to proceed in the face of errors, but it still seems pretty odd.

Are real-life UAs that parse CSS really implemented according to this (these) grammars?

EDIT: reason for the question is actually the various LESS implementations. less.js doesn’t understand consecutive comments, and lessc.exe doesn’t understand comments inside selectors. In this respect they are not even able to parse CSS correctly, however that is defined. So I went to see what the actual grammar of CSS was and …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:26:54+00:00Added an answer on May 24, 2026 at 4:26 pm

    CSS, while similar to many programming languages, does have some rare instances where whitespace can be important.


    Say we have the following base markup:

    <html>
        <head>
            <style type="text/css">
                .blueborder { width:200px; height:200px; border: solid 2px #00f; }
                .redborder  { width:100px; height:100px; margin:50px; border: solid 2px #f00; }
            </style>
        </head>
    
        <body>
            <div class="blueborder">
                <div class="redborder"></div>
            </div>
        </body>
    
    </html>
    

    There’s nothing special here, except a div inside of a div, with some styles on it so that you can see the difference between them.

    Now lets add another class and an ID to the outer div:

    <div class="blueborder MyClass" id="MyDiv">
        <div class="redborder"></div>
    </div>
    

    If I want to give a background to the outer div in the following manner:

    .MyClass#MyDiv { background: #ccc; }
    

    …then the whitespace becomes important. The rule above does style the outer div, as it is parsed differently than the following:

    .MyClass #MyDiv { background: #ccc; }
    

    …which does NOT style the outer div.

    To see how these are parsed differently, you can look at how the selectors are tokenized:

    Example1:

    .MyClass#MyDiv -> DELIM IDENT HASH
    

    Example2:

    .MyClass #MyDiv -> DELIM IDENT S HASH
    

    If we were to blindly ignore whitespace (as compilers usually do), we would miss this difference.


    With that being said, I am not implying that this grammer is good. I also have a fair amount of experience in writing grammars, and I cringe when looking at this grammar. The easiest solution would have been to add the # and . symbols into the IDENT token and then everything else becomes much easier.

    However they did not chose to do this, and the need for whitespace is an artifact of that decision.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having CSS question on aligning an element vertically. Please take a look at
I'm having a bizarre situation here where my external site files, both JavaScript and
I am having trouble getting my CSS to look right. I want alternating colors
I am having problems styling form fields with CSS. As you can see below
I am trying to create a table look utilizing CSS Divs, and Im having
I am having problems messing with some css to get it to look the
I was having a look at this tutorial at Sun on command line I/O.
I've been having a look at several MVC frameworks (like rails, merb, cakephp, codeignitier,
I've been having a look at making changes to the partial classes generated from
I am having a look af a big C++ project with more than 100

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.