Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML Treehouse Club: JavaScript Car Sounds CSS Selectors

Tyrone Sunde
PLUS
Tyrone Sunde
Courses Plus Student 6,379 Points

Tag attributes Other Than Class and ID

I've see web pages that have UID, CID and LID attributes. What are these for? Can I make up any attribute I want and put it in a tag?

3 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Tyrone,

Where have you seen attributes like these before as custom attribute names aren't supported by browsers unless you prepend data- to them which is part of the HTML5 specification, if we can see an example it will help to understand why and if they server a specific purpose or if someone has got creative.

Tyrone Sunde
PLUS
Tyrone Sunde
Courses Plus Student 6,379 Points

Hello Chris,

My company uses a browser-based reporting software called Cognos. The reports that are produced have the odd attributes in them. I'm pretty certain I have seen them in tr or td tags.

Chris Shaw
Chris Shaw
26,676 Points

That's not surprising then as most reporting software will do this, in the real world however it's not recommend and it's best to use only valid attributes or data attributes.

Tyrone Sunde
PLUS
Tyrone Sunde
Courses Plus Student 6,379 Points

Developers of the reports can put a tool in the report to enter html, CSS and JavaScript. If I could determine the pattern of attribute usage, could I use the unusual attributes in my CSS and JavaScript? If there were a tag like the following how could I act on its contents with CSS and JavaScript: <td UID=1272>7,238<td>?

Chris Shaw
Chris Shaw
26,676 Points

As I said above I don't recommend you use anything other than what's specified in the W3C specification as some older browsers don't handle custom attributes that well or at all, at least until IE 7 and 8 are at their end of life it's best to stick with the standards implemented as of now.

If you really want to use custom attributes data attributes are the way to go as they have a common standard that works and is accepted by all modern browsers, IE 7 and 8 can also use data attributes but can sometimes be annoying to get and set data on.