Mathias Bynens

HTML element + attribute notation

· tagged with CSS, HTML

Recently, a popular new addition was made to the HTML spec: anchors may now have a download attribute. That’s not what this post is about though — instead, I’d like to go over some of the different notations people used to refer to this new element + attribute combo in tweets and blog posts.

When discussing specific attributes to specific elements, it’s kinda verbose to write out e.g. “the download attribute of the <a> element” all the time. Think about it — that text alone takes up ⅓ of a tweet. Thankfully, there are some useful short notations we can use.

Instead of reinventing the wheel, let’s just stick to the XPath syntax or its simplified variation for this, ok?

Example

This short notation can be very useful at times — not only to shorten text, but also to make it more readable. Check it out:

Safari 4 and Opera 11.00 support the placeholder attribute on <input> elements, but do not support the placeholder attribute on <textarea> elements.

Becomes…

Safari 4 and Opera 11.00 support input@placeholder, but not textarea@placeholder.

Comments

Niels Matthijs wrote on :

Could be that no-one uses XPath anymore, but a whole lot of people won’t even know about XPath in the first place, making the XPath notation quite incomprehensible for people seeing this the first time around. I prefer the CSS notation as it is widely recognized and a css selector is after all just a translation of a specific HTML path.

Also, [] is easier to type than /@ :p

Mathias wrote on :

Niels Matthijs:

Could be that no-one uses XPath anymore, but a whole lot of people won't even know about XPath in the first place, making the XPath notation quite incomprehensible for people seeing this the first time around.

I wouldn’t say it’s completely incomprehensible, but I get your point. Hey, that’s why I wrote this post :) The people need to know!

Niels Matthijs wrote on :

I have no prior experience with XPath and when I would encounter tag/@attribute for the first time I’m sure I wouldn’t know what the meaning behind the notation could be. If you can make it into a standard though, that’d be fine :)

Just wondering, but does XPath have the same reach as CSS selectors for defining HTML path notations? Like how does it symbolize a class link (a.download), child nodes (.parent>.child) and such? The power of CSS notations is that it’s all there, because it’s made that way to interact with HTML.

Federico wrote on :

Niels Matthijs: XPath is even better (I believe it even has a .child<.parent selector), but I barely know of its existence, let alone how to read an XPath, and I think many are on the same boat.

Wolf wrote on :

I understand your point but now you’re just making things harder. If you’re talking about attributes on elements who not type that? Just because Twitter only supports 140 characters doesn’t mean we have to go find shortcuts for everything.

Mathias wrote on :

Wolf:

Just because Twitter only supports 140 characters doesn’t mean we have to go find shortcuts for everything.

I completely agree. Note that I’m not inventing any new shortcuts here; I’m merely documenting the XPath notation, which has been used for years now for this exact purpose (and not just on Twitter), so that hopefully people will learn to recognize and use it rather than come up with new notations.

Mathias wrote on :

Jan!: Thanks for bringing that short and sweet XPath-inspired notation to my attention — to be honest, I hadn’t seen it before. Post updated!

Joss wrote on :

What about a:download?

Or does that fall into the trap of looking too much like CSS?

I'm thinking along the lines of option:selected

niu tech wrote on :

+1 for <a download> or <a download="">! It’s the most readable, since it’s plain HTML. Much more people will recognize <a href=""> than a/@href.

Leave a comment

Comment on “HTML element + attribute notation”

Some Markdown is allowed; HTML isn’t. Keyboard shortcuts are available.

It’s possible to add emphasis to text:

_Emphasize_ some terms. Perhaps you’d rather use **strong emphasis** instead?

Select some text and press + I on Mac or Ctrl + I on Windows to make it italic. For bold text, use + B or Ctrl + B.

To create links:

Here’s an inline link to [Google](http://www.google.com/).

If the link itself is not descriptive enough to tell users where they’re going, you might want to create a link with a title attribute, which will show up on hover:

Here’s a [poorly-named link](http://www.google.com/ "Google").

Use backticks (`) to create an inline <code> span:

In HTML, the `p` element represents a paragraph.

Select some inline text and press + K on Mac or Ctrl + K on Windows to make it a <code> span.

Indent four spaces to create an escaped <pre><code> block:

    printf("goodbye world!"); /* his suicide note
was in C */

Alternatively, you could use triple backtick syntax:

```
printf("goodbye world!"); /* his suicide note
was in C */
```

Select a block of text (more than one line) and press + K on Mac or Ctrl + K on Windows to make it a preformatted <code> block.

Quoting text can be done as follows:

> Lorem iPad dolor sit amet, consectetur Apple adipisicing elit,
> sed do eiusmod incididunt ut labore et dolore magna aliqua Shenzhen.
> Ut enim ad minim veniam, quis nostrud no multi-tasking ullamco laboris
> nisi ut aliquip iPad ex ea commodo consequat.

Select a block of text and press + E on Mac or Ctrl + E on Windows to make it a <blockquote>.