Notes on XML, Elements, and Attributes
Published on April 23, 2009 (⻠February 5, 2024), filed under Development (RSS feed for all categories).
This and many other posts are also available as a pretty, well-behaved ebook: On Web Development.
Contrary to what one might expect, Iâm not bringing in much XML design experience with my occasional contributions to the HTML 5 specification. However, knowledge of the design of markup languages is something I consider beneficial for my job as a web professional as well. A few notes on XML design, inspired by internal and external documentation:
-
Attributes mean more restrictions than elements. Every XML design contains some elements. An XML design that only features elements is simplest, but not necessarily most appropriate.
-
Elements are handy if data are exposed to the user. If these data are not shown, using an attribute might be more useful.
-
Elements should be used when information is represented that can be considered an independent object, and when there is some kind of parent and child relationship.
-
Several occurrences in a data model are often better handled by elements rather than attributes. This avoids enumerated attributes like, for instance,
foo1
,foo2
,foo3
, &c. -
To order data, elements are more useful than attributes. Attributes are âinherently unordered.â
Update (November 27, 2014)
I found Uche Ogbujiâs article on principles of XML design useful, too. For example:
-
The general principle of data going into elements, metadata into attributes.
-
The principle of structured information: If the information is expressed in a structured form, especially if the structure may be extensible, use elements. But: If the information is expressed as an atomic token, use attributes.
-
The principle of readability: If the information is intended to be read and understood by a person, use elements. But: If the information is most readily understood and digested by a machine, use attributes.
-
The principle of element/attribute binding: Use an element if you need its value to be modified by another attribute.
About Me

Iâm Jens (long: Jens Oliver Meiert), and Iâm a web developer, manager, and author. Iâve worked as a technical lead and engineering manager for small and large enterprises, Iâm an occasional contributor to web standards (like HTML, CSS, WCAG), and I write and review books for OâReilly and Frontend Dogma.
I love trying things, not only in web development and engineering management, but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (I value you being critical, interpreting charitably, and giving feedback.)
Comments (Closed)
-
On April 23, 2009, 23:15 CEST, Steffen said:
My thoughts on that considering only the information structure aspects of the document:
As long as the information is and stays flat, I would prefer an attribute for brevity.
If information is extensible in nature (concerning cardinality and depth) you should opt for an element, which also contributes to simplification of validation (thinking of xsd or dtd).
That said, I canât resist to state that the style attribute must be considered as an anti pattern (I know, you will like that, Jens đ), looking at sth. like style=âa: 1; b: 2; c: url(y) #3 [âŠ];â. Itâs ignoring the (x/ht)ml grammar and starts a completely new one instead of using means of XML.
I wonder, if this would still be the design of choice today with the growing popularity of extensible (in terms of namespaces) documents - neglecting all backward compatibility and nostalgic feelings đ.
-
On April 24, 2009, 15:10 CEST, Jens Oliver Meiert said:
Interesting, thanks Steffen! Would be lovely to hear some thoughts on that from other HTML WG membersâand I can follow, but not comment on the history of
@style
.
Read More
Maybe of interest to you, too:
- Next: The Result of Maturity Is Simplicity
- Previous: Why CSS Needs No Variables
- More under Development
- More from 2009
- Most popular posts
Looking for a way to comment? Comments have been disabled, unfortunately.

Get a good look at web development? Try WebGlossary.infoâand The Web Development Glossary 3K. With explanations and definitions for thousands of terms of web development, web design, and related fields, building on Wikipedia as well as MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.