What kind of language is CSS?

CssDefinition

Css Problem Overview


What kind of language is CSS?

My first inclination was to call it a markup language... but it doesn't really fit the mold:

> A markup language is a system for > annotating a text in a way which is > syntactically distinguishable from > that text. -wikipedia

CSS uses various selectors to apply properties to elements within HTML, a markup language

Css Solutions


Solution 1 - Css

I would say it is a domain-specific http://en.wikipedia.org/wiki/Declarative_programming">declarative</a> language.

Solution 2 - Css

Syntactically, CSS is a mix of two languages: the language of selectors, which is a pattern-matching one, like regexps or xpath, and the language of properties, which can be classified as "procedural-declarative", because properties are essentially assignment operators. At a subjective level, css clearly qualifies as ugly mess, like pretty much every other fruit of collective efforts on the field of language design ("a camel is a horse designed by committee").

Solution 3 - Css

CSS is not really a language, per se; it is more of a syntax for describing configuration directives.

In fact, it is neither of these things; CSS is a description of a number of tokens and their visual meanings; .css files contain these tokens structured in manner allowing a computer to parse them. CSS declarations can take the form of name="value" declarations in SVG documents; and the .css file structure could just as easily be employed to, say, contain unit descriptions in a particularly absurd iteration of FreeCiv.

Wikipedias definition of it as a Style sheet language seems like a bit of a forced definition of a generalization of a singularly existing phenomenon; and it should be clear that it is not in any way a markup language, as it doesn't actually, by itself, mark anything up.

Solution 4 - Css

CSS is most definitely a language:

Wikipedia refers to css as a 'style sheet language'

http://en.wikipedia.org/wiki/Style_sheet_language

Also from W3C who developed CSS: (comparing [tag:XSL] and [tag:CSS])

>The unique features are that CSS can be used to style HTML & XML documents. XSL, on the other hand, is able to transform documents. For example, XSL can be used to transform XML data into HTML/CSS documents on the Web server. This way, the two languages complement each other and can be used together.
> >Both languages can be used to style XML documents.

As you can see from the second sentence W3C refers to CSS as a language.

http://www.w3.org/Style/

And the next quote again from the same article:

>The fact that W3C has developed XSL in addition to CSS has caused some confusion. Why develop a second style sheet language when implementers haven't even finished the first one? The answer can be found in the table below:

                            CSS     XSL
Can be used with HTML?      yes      no 
Can be used with XML?       yes     yes
Transformation language?     no     yes
Syntax                      CSS     XML

Solution 5 - Css

CSS has a well-defined grammar, thus it is a language, and if you had to choose between CSS being declarative or imperative, then it would be declarative, as the results of its operation are determined by the program actually interpreting and processing the CSS.

However, you can't build anything useful with CSS alone; it needs a document to operate on, and all the CSS does is provide supplemental information for the document; effectively, then, the CCS is a part of the document it operates on.

The problem with CSS is that is it used as part of the HTML to DOM generation process; therefore CSS behaves similar to "messy" global variables, and as a result, developers have to deal with the plethora of nasty side effects CSS brings along with it.

Hopefully, Håkon Wium Lie, the inventor of CSS, and a major player at the W3C will one day come to realize that CSS was and is a mistake from the beginning until today and the wrong path to take to achieve a separation of semantic markup and presentation.

Today, CCS is gaining imperative features with @media queries, and targeting with @operators, such as @screen and @print. But none of the new features will correct the fundamentals flaws of CSS: the god-awful globals, and the notorious unreasonable use of side-effects with its element selectors.

Unfortunately, the study of CSS as a language is more complex than the study of real programming languages, as examples of how to use it are more anecdotal than practical, hence the need for comprehensive CSS frameworks like Bootstrap and others to get your job done.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDerek AdairView Question on Stackoverflow
Solution 1 - CssNick Van BruntView Answer on Stackoverflow
Solution 2 - Cssuser187291View Answer on Stackoverflow
Solution 3 - CssWilliham TotlandView Answer on Stackoverflow
Solution 4 - CssdkinzerView Answer on Stackoverflow
Solution 5 - CssWillie LView Answer on Stackoverflow