You may prefer the regular "data-" prefix ( https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Usin... ) to "am-", especially if you want to be compatible with React.
You can definitely do this, though I think "data-am-" is better to avoid conflicts. React ignores unexpected attributes at the moment, but can't forever with Custom Elements (since it can't know what valid attributes for new elements are). We've got an open discussion on this point, if you want to contribute there: https://github.com/amcss/attribute-module-specification/issu...
AM – Attribute Modules for CSS
11–20 of 58 posts
Re: AM – Attribute Modules for CSS
#12Very interesting approach. One small peeve: this method will not allow you to use Sass/LESS nesting.
[foo] {
color: blue;
background-color: pink;
.bar .baz {
[qux~="ok"] {
color: red;
}
}
}
compiles to [foo] {
color: blue;
background-color: pink;
}
[foo] .bar .baz [qux~="ok"] {
color: red;
}
as I'd expect.Re: AM – Attribute Modules for CSS
#13Very interesting approach. One small peeve: this method will not allow you to use Sass/LESS nesting.
why wouldn't it? Attribute selectors are just selectors. [foo] { color: blue; background-color: pink; .bar .baz { [qux~="ok"] { color: red; } } } compiles to [foo] { color: blue; background-color: pink; } [foo] .bar .baz [qux~="ok"] { color: red; } as I'd expect.
Re: AM – Attribute Modules for CSS
#14This looks a promising approach to the chaos that is writing reusable and maintainable CSS. I wonder about performance though, especially on mobile. Will this perform as good as regular class-written CSS, even if you have >2000 loc CSS files?
Not a chance, browsers can optimise lookup for ids and classes (or even elements by name) because they have spec-defined semantics, and they can be preprocessed based on those semantics (e.g. used to key maps). Custom attributes have arbitrary semantics, so they can't be fit into such a static structure. Technically nothing prevents browsers from inferring specific behaviors from the way a custom attribute is used, a…
Re: AM – Attribute Modules for CSS
#15Earlier quoted context omitted.
You can definitely do this, though I think "data-am-" is better to avoid conflicts. React ignores unexpected attributes at the moment, but can't forever with Custom Elements (since it can't know what valid attributes for new elements are). We've got an open discussion on this point, if you want to contribute there: https://github.com/amcss/attribute-module-specification/issu...
"data-am-" would be a good choice indeed :)
Re: AM – Attribute Modules for CSS
#16interesting approach! any real web/app using this technique?
Re: AM – Attribute Modules for CSS
#17This looks a promising approach to the chaos that is writing reusable and maintainable CSS. I wonder about performance though, especially on mobile. Will this perform as good as regular class-written CSS, even if you have >2000 loc CSS files?
Performance of long CSS files isn't really the (major) concern —its how many _elements_ are being traversed (size of the dom) that really effects CSS-selector performance.
Performance has improved a bit since this post but it's still relevant: http://perfectionkills.com/profiling-css-for-fun-and-profit-...
Re: AM – Attribute Modules for CSS
#18Re: AM – Attribute Modules for CSS
#19interesting approach! any real web/app using this technique?
eg. 
Aside & max500px were then picked up the CSS using the images alt attribute as the selectors.
It was a terrible hack but it worked.
Re: AM – Attribute Modules for CSS
#20Honestly, what problem is this actually solving?
You have .foo, .foo--bar, .foo--extra, and you're concerned the style tags are what... not pretty enough? Too hard to visually parse? Too complex when you're building a large css framework?
I really don't understand the problem.
...but having worked with tal, I can hands down say I hate the custom attribute syntax; it scatters the style into multiple locations and makes it unclear what parts are data and what parts are presentation.
I thought we all agreed that:
Its 1998! Hi!
Was a bad thing. (and that was fifteen years ago... lessons from the past or whatever...)