All posts tagged ‘CAS’

File Under: Web Standards

Like CSS? Then You Might One Day Enjoy ‘Cascading Attribute Sheets’

But maybe Cascading Attribute Sheets can. Image: Noah Sussman/Flickr

Cascading Stylesheets are awesome, why not take the same idea and apply it to HTML attributes?

That’s the question the W3C’s WebApps Working Group has been pondering ever since Tab Atkins Jr., a Google representative at the W3C, proposed an entirely new web language — Cascading Attribute Sheets, or CAS for short.

Atkins proposes that CAS use more or less the same syntax as CSS, but apply the concept to HTML attributes. The key difference, which limits CAS slightly, but which would keep it speedy, is that CAS would run once, when the element is added to the page, with no dynamic changes after the fact.

Here’s how CAS would work in practice: first, you would include a link to your CAS file using a <script> tag. Then, assuming you have a video tag on your page, you might do something like this in your CAS:

 

video {
    preload: metadata;
}

These lines would add the preload attribute to all your video tags and set the value to metadata. What if you want to target just the video tags inside your main content container? No problem, just use the same selector nesting you’d use in CSS:

#content video {
    preload: auto;
}

This would target only video tags inside the #content container, this time setting the preload attribute to auto.

To make CAS as simple as possible for both browser makers and developers it would very closely mirror CSS. “In the place where CSS normally has a property name, CAS allows any attribute name,” writes Atkins on the W3C mailing list. For an attribute value CAS allows “any single token, such as a number, identifier or string.” In theory this would allow CAS to reuse the browser’s CSS parser, limiting the amount of work necessary to get browsers to support CAS.

Atkins hopes that “by reusing the CSS parser and restricting all the expensive parts of CSS (dynamicness, remembering where a value came from, etc.), I can pull the bar down low enough for this to make it… It is just sugar, but it’s useful sugar, as evidenced by the fact that people keep trying to push content attributes into CSS.”

However, Maciej Stachowiak, an Apple representative at the W3C, questions whether or not CAS would work with WebKit’s CSS parser writing, “I doubt we would be able to actually reuse the CSS parser, at least at the code level, at least for WebKit.”

Whether or not Atkins’ proposal is ever accepted, or if browsers would ever support it, remains to be seen, but now that the tantalizing idea has been planted in our heads we’re really hoping it catches on. For more on the fate of CAS and some discussion of its potential inner workings, have a look at the full thread on the W3C mailing list.