At a recent interview I was asked the question \"Is CSS giving error?\" by the interviewer.
Is there an interpreter working behind CSS which blocks
I think the question is too broad and not specific. This is how I would have answered the question.
Is CSS giving error ?
Depends on the place you are looking at. In a IDE? sure it will show you validation errors. In browser? Most browsers tend to ignore CSS validation errors and continue with rest of the rules.Again as @Kishan Choudhary mentioned in another answer "CSS" refers just the styling language and languages cannot prompt you errors by themselves.
Alt. Question: How can we validate/debug/find errors in a CSS?
Can we say that CSS does not give any error?
Again it depends on the place you are looking at. In development environment? Yes almost all web IDEs will help you to find your CSS mistakes.
In Client browser? Not so much,You can open browser console/developer tool if available and there might be logs errors, for example invalid or unreachable URLs of images you have used in CSS. Again is it a CSS syntax or validation error?nope
Is there an interpreter working behind CSS which blocks execution of the program?
Yes every browser has an inbuilt CSS interpreter/parser following W3C standards and does it like to block execution?No,normal behavior of all most all browsers is to that ignore (not to block interpreting and applying remaining valid style rules) CSS validation errors and continue with rest of the rules.
Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification
4.2 Rules for handling parsing errors
In some cases, user agents must ignore part of an illegal style sheet. This specification defines ignore to mean that the user agent parses the illegal part (in order to find its beginning and end), but otherwise acts as if it had not been there. CSS 2.1 reserves for future updates of CSS all property:value combinations and @-keywords that do not contain an identifier beginning with dash or underscore. Implementations must ignore such combinations (other than those introduced by future updates of CSS).
To ensure that new properties and new values for existing properties can be added in the future.
CSS Syntax Module Level 3
2.2. Error Handling
When errors occur in CSS, the parser attempts to recover gracefully, throwing away only the minimum amount of content before returning to parsing as normal. This is because errors aren’t always mistakes - new syntax looks like an error to an old parser, and it’s useful to be able to add new syntax to the language without worrying about stylesheets that include it being completely broken in older UAs.
CSS is not a real programming language but a domain-specific language (https://en.wikipedia.org/wiki/Domain-specific_language).
In contrast to scripting languages like JavaScript or PHP (which are Turing-complete programming languages) as well as real programming languages like Java or C CSS will not "give errors" as CSS-code is not real program source code.
However as any domain specific language CSS has a syntax and is read by an interpreter (very similar to a declarative Turing-complete programming language).
If the syntax is not correct (test here: https://jigsaw.w3.org/css-validator/#validate_by_input) the CSS is invalid. It depends on the interpreter used how to deal with invalid CSS parts, interpreters in common Web browsers will not halt on CSS syntax errors.
This question therefore can not be explicitly answered:
In the conclusion I can say in @Kishan Choudhary's words "Is CSS giving error ?" - No
but there may be parsing and browser giving errors.
These points are help me to got conclusion.
Thanks guys.
No, "CSS does not give error," but I think that the interviewer may have been mis-stating the question.
If the interviewer was not mis-stating the question, then we can definitively say that no, CSS does not give errors. There is no evaluator or compiler in the CSS spec that scans your cascade looking for errors. It could even be argued that browsers do not have error handling for CSS, as all commonly used browsers actually discard erroneously written declarations and then search for the nearest semi-colon, and then go back to the reading cascade.
Tab Atkins Jr has a good explanation of how browsers handle errors in CSS and why they handle them that way.
If the browser is in trying to parse a declaration and it encounters something it doesn't understand, it throws away the declaration, then seeks forward until it finds a semicolon that's not inside of a {}, [], or () block.
So if the interviewer was trying to play gotcha with this question, I think you could confidently answer that no, CSS is not giving error. But, there's a decent chance that the interviewer may not really understand CSS or how browsers interpret CSS and wants you to find the errors in a block of CSS. Never be shy to ask an interviewer what they might mean when they ask a question, or if it doesn't sound clear to you.
CSS itself will not give an error, however CSS which has an error in its syntax will not render correctly. The browser may not be able to understand what is meant at a given point, and therefore not be able to format the page correctly.
There's also a difference in CSS being syntactically correct, where everything is properly enclosed and lines terminated, and it being standards compliant according to the W3C specification.
EDIT : (example for syntax correctness and standards compliance) The following is an example of syntactically correct CSS, which won't fail validation on the W3C CSS Validator:
p.my-class {
color : red;
-moz-border-radius : 3px;
}
Whilst this is technically valid CSS, according to the vendor specific extensions section of the CSS 2.1 syntax, they should be avoided. It's the initial dash or underscore which lets them be valid.
The answers depends on how you define Error.
If Error means happening of something unexpected, then CSS surely gives errors, cause, it wont work if you have something wrong in the syntax.
If Error means throwing something to browser or console, CSS doesn't do so.
If Error means something which breaks the workflow and stops the execution of the next part of codes, CSS doesn't.
If you consider point 2 and 3, you may consider CSS errors like warnings in PHP or other programming languages. Only difference is that, in PHP we have option to turn them on to throw something in the browser. CSS doesn't have any such option till now.