Rutwick Gangurde Rutwick Gangurde - 7 months ago 19
HTML Question

What does the html 'typeof' attribute do?

I recently came across a question on SO in which

typeof="foaf:person"
was used as an attribute for an element. I Googled for it but this was the only relevant result. This fiddle too uses the
typeof
attribute. Would some one please explain me how and why this attribute is used?

Answer

It's not a HTML attribute, it's RDF, an unrelated markup language, that happens to be usable as part of HTML or XHTML. It's used to specify more metadata to your data. One of the namespaces of RDF is FOAF (that's your foaf:person), described here - http://xmlns.com/foaf/spec/.

It's part of the "semantic web movement", which basically tries to include semantic information about the web data (the same way HTML5 added eg. the article tag). So by tagging eg. a span with your attribute, you're saying that the content of that span should be interpreted as a person, and by adding more attributes, you can tell that something is that person's name, or homepage etc. This allows for easy understanding of data, especially for machines, and removes some of the ambiguity.

Comments