Menu Search
Jump to the content X X
Smashing Conf New York

We use ad-blockers as well, you know. We gotta keep those servers running though. Did you know that we publish useful books and run friendly conferences — crafted for pros like yourself? E.g. upcoming SmashingConf New York, dedicated to smart front-end techniques and design patterns.

The Poetics Of Coding


There is little doubt that WordPress is one of the most popular blogging and content management platforms out there today. This is not an article about WordPress, though, but rather a more general musing on one of its thought-provoking taglines: “Code Is Poetry.”

That’s an interesting metaphor. Recently, I’ve written about the different languages1 used by designers and developers, and also about the relationship2 between these coding languages and proper human language (specifically, English). As someone who graduated from university with a degree in English Literature and came to Web design in a roundabout way, this kind of thinking has always interested me.

As has this apparent connection between code and poetry. What does the metaphor mean? I took some time to really think about this relationship and discovered that the people at WordPress got it right (again). Code really is similar to poetry!

A Superficial Similarity Link

To start off, code and poetry have a somewhat obvious and entirely superficial similarity, and we may as well begin there. Here is a poem I wrote a few years ago:

A man in a suit,
standing on an old stone bridge,
sees the reflection
of himself in the water
flowing, unhindered, below.

I promise this will be the only work of mine that I include here, but let’s compare it to some snippets of simple code, starting with HTML:

  <div id=”content”>
    <h1>The Title</h1>
    <p>Some content</p>

Now look at some CSS:

div {
  border: 1em 0px;
  background-color: #444
  border: 1px solid #222;

And finally some JavaScript:

function cubeMe(x){
  var answer = x*x*x;

I want to highlight two key elements: the short lengths and the prominent indentation. These are both common elements of poetry and code (though not absolutely necessary to either).

This comparison is superficial at best, and there is a much stronger connection to explore. Still, this basic similarity reveals a certain visual relationship between code and poetry, which gives us an interesting entry point to discuses the subject.

A Master’s Art Link

This code-is-poetry metaphor comes at least partly from a perception of poetry as the master’s craft. Whether you love or hate it (and I know a lot of people hate it), there has always been a general sense that poetry sits at the apex of the written word, as though poets sit in an ivory tower, composing lines with a golden pen.

Of course, the reality is strikingly different. A lot of really bad poetry is out there, written by people who call themselves poets just because they can rhyme words at the end of two lines.

Does that sound familiar?

How similar is this to the proverbial “nephew”? You know the one: that kid who read the introduction to a high-school textbook about the Web, figured out a few HTML tags and is now driving you crazy with his offer of a “Web design” for $100 and a six-pack of beer. Makes you want to tear your hair out, doesn’t he?

Anyone who has been at this Web design thing for a while (or at least anyone who takes themselves seriously) would agree that there’s more to the job than hacking out content wrapped in a bunch of poorly structured and entirely non-semantic HTML. For those of us who strive to be masters of our craft, code is so much more.

Code has purpose and meaning. It requires structure. It should be lightweight and elegant, not bogged down with lines and lines of garbage. Writing great code isn’t something that just happens. It takes discipline and work! It’s an art unto itself.

Feeling impassioned yet? If so, you might have the heart of a poet. I’ll tell you why.

Of Pen And Purpose Link

Every good poem has a purpose. The purpose need not be so lofty as to change the world or to establish a new school of thinking, but every good poem needs a purpose. Of course, nothing is surprising about this. Many mediocre and poor poems are written with a purpose. The difference is in execution.

If a poem is written for a particular purpose, then the composition should reflect that purpose. The structure, word choice, subject and tone should all work together to support the primary purpose. For example, the purpose of Coleridge’s “Kubla Khan” is to capture the imagery of one of the poet’s (opium-induced) dreams. It famously opens:

In Xanadu did Kubla Khan
A stately pleasure-dome decree:
Where Alph, the sacred river, ran
Through caverns measureless to man
Down to a sunless sea.

The poem continues on in much the same tone, fully of lyrical and Romantic language by which Coleridge captures the essence of his dream. His word choice and form help the poem achieve its purpose.


A limerick is a different kind of poem altogether, one generally intended to be witty or humorous (and sometimes just plain crude). Here is one of the limericks I remember best:

There was an old man from the Cape,
Who made himself garments of crepe.
When asked if they tear
he replied, “Here and there,
But they keep such a beautiful shape!”

All limericks follow this structure and share this cadence, which contribute to the overall effect. The rhythm makes the text sound silly and light-hearted, whatever the actual words. While the poem is vastly different from Coleridge’s Romantic vision, it too demonstrates a keen understanding of its purpose.

Our code should be much the same. Different kinds of code serve different purposes and should be used accordingly. In Web design, the most cliched example is using tables for layout purposes. The HTML table tags were intended to present information in tabular format, not to structure an entire document. Using it in the latter way is a misappropriation of its purpose.

Any experienced coder would attest that tabular layouts are far more inflexible than CSS. They really limit you to the confines of the table itself. Styles, however, give you a great deal more flexibility and allow you to do a lot more. We may harp on about it a lot, to the point of being annoying, but it’s a perfect example of how failing to understand purpose can render code less effective!

CSS also provides a great example of the difference between inline, embedded and external styles. Each has a different purpose, and using it the wrong way can really weigh down your code. The external style sheet is used to implement universal styles that can be applied to an entire website (or, in some cases, multiple websites). The embedded style sheet, which is less frequently used, overwrites external styles. This is great for custom artistic posts. Inline styles can be used to overwrite the styling of a single element.

It’s all pretty straightforward for a seasoned Web designer. For the uninitiated, though, mixing up these purposes is all too easy, and it potentially results in bloated code, full of unnecessary inline styling and redundant elements, all from a lack of understanding CSS’ rules of precedence.

So, whether you code HTML or CSS, if you believe in the importance of understanding your purpose, then you certainly have something in common with the great poets.

Meaning Link

Another important aspect of poetry is meaning. Like any text, a poem means something on the surface: it literally means what it says, even if what it says is sometimes difficult to understand (especially with some archaic works). However, a good poem always has a secondary meaning, hidden beneath the surface.

The incomparable Robert Frost demonstrates this, in a stanza from his popular “Stopping by Woods on a Snowy Evening:”

The woods are lovely, dark, and deep,
But I have promises to keep.
And miles to go before I sleep,
And miles to go before I sleep.

On the surface, the poem’s closing lines simply state that the narrator thinks the woods are lovely but that he has promises to keep and a long journey before he gets to bed. But there is also critical discussion about the meaning that lurks below the surface of these lines. Not to go into too much analysis here, but it has been suggested that these lines indicate a deep yearning in the narrator to abandon the responsibilities of society and retreat to the embrace of nature, possibly even to death.


Again, code can be very similar, though in a different way. Instead of having a surface meaning and an underlying meaning, code (and specifically HTML) creates meaning through both its semantics and its structure. For example, consider these two lines:

<p>The Wasteland</p>
<h1>The Wasteland</h1>

The content is identical, but the context created by the mark-up is entirely different. In the first instance, the content is a paragraph (or simple body text). In the second, it is a first-level heading. The two are very different. Here’s another example:

<p>This is a paragraph.</p>
<p>This <em>is</em> a paragraph.</p>

The first sentence is a simple statement. But the emphasis in the second sentence on the word “is” changes the meaning. Now it becomes more of an affirmation against the (quite legitimate) claim that a single sentence does not really constitute a paragraph. Also, notice the choice of tag, using the semantic em tag for emphasis, instead of the simple italics tag.

Similarly, a language such as PHP provides contextual meaning through conditional logic. For example, here is a snippet of WordPress code that I often use to generate the content of the title tag:

  echo "Home :: ";
  echo the_title() . " :: ";
  echo the_title() . " :: ";
  echo single_cat_title() . " :: ";
  echo "Articles tagged as "";
  echo single_tag_title() . "" :: ";
  echo "Articles posted in ";
  echo the_time('F, Y') . " :: ";

In this case, the code produces a different title, based on the type of content being generated. It’s much different than our HTML example, but it still demonstrates the ability of a block of code to provide extra meaning to content—the same way that a poem’s subtext adds a layer of meaning below the surface.

The Importance Of Being Structured Link

A key similarity in the code-as-poetry metaphor is the need for structure. Poetry is traditionally a very structured form of writing. Take the sonnet, which was once widely considered one of the most elevated forms of poetry and is quite difficult to write (trust me, I’ve tried). Here is Elizabeth Barret-Browning’s famous “How Do I Love Thee”:

How do I love thee? Let me count the ways.
I love thee to the depth and breadth and height
My soul can reach, when feeling out of sight
For the ends of Being and ideal Grace.
I love thee to the level of everyday’s
Most quiet need, by sun and candlelight.
I love thee freely, as men might strive for Right;
I love thee purely, as they turn from Praise.
I love thee with the passion put to use
In my old griefs, and with my childhood’s faith.
I love thee with a love I seemed to lose
With my lost saints,–I love thee with the breath,
Smiles, tears, of all my life!–and, if God choose,
I shall but love thee better after death.

This poem, which appears on so much sentimental merchandise these days, follows the sonnet structure very closely. It has the standard 14 lines, with a specific rhyming structure. For the most part, it also follows the traditional meter, called iambic pentameter. I won’t break down the sonnet’s adherence to and deviation from traditional structure (because I would probably lose your interest). Suffice it to say, this poem is constructed on a very strict and rigid scheme.


There are other types of poetic structures, too, such as the brief haiku and the silly limerick (which we looked at). Some might suggest that much modern poetry is even more “free” and unstructured. This may be the case with lesser poems, but not with the best modern works. While these poems may appear not to follow a pattern, they are always structured in some way. You just have to look harder to find it.

The structure of code, though, is very obvious—in fact, probably more so than the rigid sonnet form. Let’s look at a basic HTML document:

    <title>A Simple Document</title>
    <h1>A Simple Document</h1>
    <p>This is just a simple document.</p>

As with the sonnet, a clear structure is at work here, one that is significantly different. The html, head and body tags all give form to the document as a whole, while the title, h1 and p tags wrap and semantically define different bits of content. For every opening tag, there is a closing tag, appearing at the appropriate place in the document’s hierarchy. It’s all basic HTML.

It’s also highly structured, and without this structure, the code degrades. In some cases, it could be a semantic issue, which often goes unnoticed, because browsers will usually correct these issues. For instance, we all know that the title tag should appear between the head tags, right? Well, if the title tag is placed somewhere else, most modern browsers will still understand the tag and render it properly. Semantically and structurally, though, it’s all wrong.

The same is true of improperly nested tags. Something like the following would likely render properly in the browser:

<p>A link to <em><strong><a href="">Smashing Magazine</em></strong></a></p>

And yet, it is structurally flawed, because tags should always be closed in the order that they were opened. Of course, things get really dicey when tags are unbalanced or when block-level elements intersect. I can’t be the only one who has been hijacked by a rogue div tag!

The point here is not to dig into the structural semantics of HTML, but to emphasize the importance of the structure in both code and poetry. If you’re nodding along with me here and agree on the importance of properly structured documents, then that’s another trait you share with poets and another bit of support for our code-is-poetry metaphor.

Trim And Efficient Link

Finally, in a well-crafted poem, every single word has meaning and purpose. Despite what may appear to be overly complex words or flowery lines, the entire piece is meticulously crafted. A poet can spend hours struggling for just the right word, or set aside a poem for days before coming back to it for a fresh perspective.

Let’s look at another of Robert Frost’s shorter works, this one entitled “Fire and Ice”:

Some say the world will end in fire,
Some say in ice.
From what I’ve tasted of desire
I hold with those who favor fire.
But if it had to perish twice,
I think I know enough of hate
To say that for destruction ice
Is also great
And would suffice.

It may be somewhat grim, but it is also exceptionally well crafted. Each word here is so carefully placed that not a single one could be removed without detracting from the meaning of the poem.

Ezra Pound’s “In The Station of the Metro” is even more succinct:

The apparition of these faces in the crowd;
Petals on a wet, black bough.

In just two lines and fourteen simple words, Pound paints a striking image, ripe with meaning and begging to be devoured by scholars and critics. Now, that’s efficiency.


Would you not agree that the same should hold true for code? Shouldn’t every tag, selector, rule and line of PHP have an explicit purpose? Unfortunately, making HTML and CSS bloated with unnecessary tags and styles is all too easy. Take this code:

  <p><span>This is a paragraph.</span></p>

div{margin: 1em 20px}
div p {font-family: sans-serif; font-size: 14px}
div p span {color: blue}

Now, compare it to this:

<p>This is a paragraph</p>

p{margin: 1em 20px; font-family: sans-serif; font-size: 14px; color: blue}

Assuming no extra margins or padding are applied to the original div, the second bit of code will render exactly the same as the first—a more economical way to achieve the same result.

As we mentioned in the section on purpose, code can also become bloated by unnecessary inline styles, where an external or even embedded style sheet would be more efficient (depending on the purpose, of course). Yet another example would be to use the onmouseover event to execute simple JavaScript effects that could be achieved more efficiently by CSS.

For the master craftsperson, great code and great poetry are lean and trim, with no excess of words or other unnecessary elements.

Conclusion Link

Part of the beauty of metaphor is its ability to highlight meaningful similarities between two seemingly unrelated ideas. Still, I have to admit that when I really considered this code-is-poetry metaphor, I was surprised by just how deep the similarities run. In some ways, the metaphor almost blurs into reality.

Perhaps code really is a form of poetry, and the coder a new kind of poet.

What does it all mean? I can’t answer that entirely, at least not here and now. But if more people regarded code as its own kind of poetry or at the very least put the two on more even footing, it would raise the bar and lead to higher-quality work. And that would only be a good thing!


Footnotes Link

  1. 1
  2. 2
SmashingConf New York

Hold on, Tiger! Thank you for reading the article. Did you know that we also publish printed books and run friendly conferences – crafted for pros like you? Like SmashingConf New York, on June 14–15, with smart design patterns and front-end techniques.

↑ Back to top Tweet itShare on Facebook

Matt Ward is a physical product entrepreneur and crowdfunding expert behind Art of the Kickstart, a podcast and blog on all things crowdfunding. He is also highly involved in the world of Amazon sales building his own brands and cofounder of Amazooka, an Amazon on Autopilot software tool and podcast to help private label product entrepreneurs automate and scale their businesses.

  1. 1

    Haha for the first time I’ve seen my language on SM – looks like the photo in “Meaning” is from czech grammar dictionary =)

  2. 2
  3. 3

    Thomas McGee

    May 5, 2010 5:47 am

    Interesting article, and very creative. A nice out-of-the-box look to coding.

  4. 4

    “His word choice and form help the poem achieve its purpose.”

    Strange, I don’t remember Coleridge being quite so sarcastic about the failings of management to quantify caverns when I last read it.

  5. 5


    May 5, 2010 5:59 am

    Awesome post, Matt. I love this kind of “out-of-the-box” thinking! And if this kind of in-depth analysis doesn’t get people to re-evaluate their code grammar, then nothing will!

  6. 6

    Oh no, not the “Like”-Button again. I want my star-rating back.
    Thats the same crap on youtube now. Complete nonesense.

    Sorry for offtopic. But I had to say that.

    By the way. Nice article.

  7. 7

    fantastic and very creative article:)

  8. 8

    Chris Teague

    May 5, 2010 6:17 am

    Interesting perspective. At the end of the day the master craftsman isn’t building code for other craftsmen but an experience for a user – don’t lose sight of the bigger picture!

  9. 9

    Tomáš Kapler

    May 5, 2010 6:21 am

    two offtopics:
    1. Where did you get Czech-English dictionary? I love this connection of my favourite ezine with my mother language ;)
    2. You are not using wp_title filter for creation of wordpress title? What an old-school way ;)

  10. 10

    “Caverns measureless to management”?

    Really? Get some analytics code installed on those caves ASAP!

    This reminds me of that extremely valuable review of Tuscan Whole Milk, 1 gal., 128 fl.oz. on Amazon — — which begins:

    In Xanadu did Kubla Khan
    A stately dairy-house decree…

  11. 11

    Wonderful article. It’s great to see people look at the more philosophical side of things.

  12. 12

    Didier Durandet

    May 5, 2010 6:35 am

    var esoterism:string=null;

    if (poetry>esoterism) {

    function specule(poem:poetry) {
    bank.push (;
    if (bank.value()>business) {

    function sell(poem:poetry) {

    // Comment :
    // May be ‘Art’ is a coding activity
    // May be poetry is juste a status…

  13. 13

    Adit Gupta

    May 5, 2010 6:50 am

    I would like to bring a different viewpoint in terms of Beautiful code or Poetic code. I agree that it’s a good practice to write proper structured code which is clear and readable. However, this is not exactly the meaning of beautiful code. I would like to echo the thoughts of Jeff Atwood on this topic – “The beauty of code lies in the architecture, the ideas, the grander algorithms and strategies that code represents.” A truly beautiful code will amaze you at how brilliantly some complex functionality was achieved or how beautifully an algorithm was implemented. The structure and clarity is like make-up, which does not essentially represents the true beauty of a code.
    I agree that the points raised in this article are true for HTML and CSS, which are NOT programming languages. In this case, it’s all about structure and clarity.
    However, a “Beautiful code” has a different meaning when it comes to programming languages [Turing Complete].

  14. 14

    Dude, whatever you’re smoking, smoke less.

  15. 15

    Mick Foley

    May 5, 2010 7:18 am

    I’ll have what you’re smoking.

  16. 16

    Hihi the top Image text is Hungarian. This book is hungarian. Thats is cool.:D

    “egy jós vers értelmezése körül….

  17. 17

    (off topic also) Atleast on Youtube you get the option of disliking something -_-.

  18. 18

    I’ve always love that little quote on WP and it provoked some serious thoughts about coding while on the john. Lovely article. Thank you!

  19. 19

    Timothy Ritter

    May 5, 2010 8:46 am

    I believe for the first time ever, I have a deeper appreciation for poetry.

  20. 20

    Bizarre stuff. May I have some of the stuff you’re smoking, because I have not read anything more absurd than this in quite a while.

  21. 21

    Thanks for these interesting thoughts, Matt. I think the best coders are very careful about structure, and good structure makes code easier to revise and understand. I also think it’s very appropriate that you included a couple of examples from Robert Frost, who was classically trained and a lifelong student of classical forms like the sonnet. In talking about the benefits of working within a rigid structure, Frost once compared it to a horse learning to “run light in harness.” I’ve always liked that metaphor.

  22. 22

    At little too philosophical for me; it’s just code. Code = means to an end, for most of the world.

    But an interesting topic; one that’s not covered much!

  23. 23

    Phil Barnhart

    May 5, 2010 9:38 am

    var man = “nantucket”

  24. 24

    For sure: code in a form of poetry.

    I always felt that way and it was amazing to read the article and see that there are more people that think the same way.

  25. 25

    Great article. Loved the ending and I completely agree. If people could and would recognize the impalpable value of good code it would help elevate the profession as a whole.

    However, following the same metaphor for code as poetry, there are very few people who can really recognize great poetry. Only those who have studied it for years can begin to understand its true value and fathom its far reaching effects.

    And so it is with code.

  26. 26

    You nailed it. I couldn’t agree with you more.

  27. 27

    i’m sure this was a great read, but it was so darn long…

  28. 28

    This article is absolutely amazing – I Love the stress of importance on how you dedicated so much attention on the proper use of language as it was intended to be used. I personally find that I’m able to actually code much faster in development and re factoring when my code is semantic and the JavaScript is unobtrusive not to mention when I have to work with another’s code.

    – Excellent Work!

  29. 29

    Dude, wtf? By your logic, man == nantucket which is a clearly horrendous bug and not at all what you want to do. A multidimensional array is what you’re after:

    Nantucket = array(array(‘man’,’bucket’),array(‘gran’,’rocket’));

  30. 30

    You messed, man. You realllly messed.

  31. 31

    Your comment is the shit-tiest comment here..

  32. 32

    couldn’t agree more.. anyone who has ever tried to do something behind the scenes (excluding wp devs alone, who also realize this but manage to cope with their own code) hasn’t got nice words for wordpress code. starting with mentioned jeff atwood, but him not being alone here

    as far from poetry as it can get is the WP code, let alone pretty output HTML formatting as a result of the running code… the tagline is pretty much an irony of itself in this case :)

  33. 33

    Great article

    I was an English major in college, and have been a programmer now for going on 13 years. I didn’t turn on a computer in college unless it was to write an essay.

    People often ask me how i ended up writing software what with my English degree. I always explain the aspects of strong literature – structure, clarity, etc. – are also the aspects of strong code.

  34. 34

    I’m going to play the Devil’s advocate here. Personally, I’m getting tired of the trend of referring to code as art or poetry. The purpose of art is to convey beauty and meaning and to provoke thought. Poetry actually encourages the bending and breaking of a language’s grammatical rules and vocabulary.

    The purpose of code is to provide an interface through which a programmer can provide instructions to a computer. The structure must be sound so instructions can be transmitted in a fixed fashion–so nothing is ambiguous; nothing can be interpreted in more ways than one. That is in stark contrast to all forms of art, wherein meaning is often intended to be ambiguous in order to provoke discussion.

    Yes, there are similarities between code and poetry. They’re both composed of languages which use a set of rules. They both have structure. They both convey meaning. Those similarities are common among any forms of communication which use written language. Therefore, it might make sense for me to claim that “Code is Chinese.” Why not? They both use symbols, have structure, obey grammar rules, and convey meaning. If that seems silly to you, then you’re getting my point.

    So please, let’s stop kidding ourselves. Code is not poetry, nor is it art. It is science. It is fixed communication–simplified language. Software can be art! We’ve all probably played games or seen animations which were beautiful. So in that sense, code is the language we use to write a poem; code is the paintbrush we use to paint a picture. If art is anywhere, it’s inside us, and inside what we produce.

  35. 35

    Coleridge defined poetry as ‘the best words in the best order’. That’s got to be a perfect definition for code too, right?

  36. 36

    Thanks Matt for this wonderful comparison and intriguing thoughts! Made my day!

    eliZZZa from Vienna

  37. 37


    May 5, 2010 1:51 pm

    Your logic seems to be misplaced a bit. If we’re going on analogies here, then yes, you’re right “Code is Chinese” but it is the WAY we write said code that can turn it into digital poetry. Words are the code, but it is the way we arrange the “words” that turns them into poetry.
    Yes, our code is meant for machines; no argument there. But we’re the ones that write it, edit it, maintain it.

  38. 38

    Billy Kzov

    May 5, 2010 1:53 pm

    You are so fugging wrong.

  39. 39

    Niels Matthijs

    May 5, 2010 2:05 pm

    >> Assuming no extra margins or padding are applied to the original div, the second bit of code will render exactly the same as the first—a more economical way to achieve the same result.

    (Might have been mentioned already)
    Actually, since you’re applying a font + em-margin on the same element in your second example, the rendering might differ 1px on top and bottom from the first example, where the font won’t effect the margin on the surrounding div.

    But anyway, html is not about economic styling, it’s about structure and semantics. So if your div could hold one or more elements besides that p which are by themselves related to the paragraph, the div is still probably the better option.

  40. 40

    Hey all. Thanks for all the really interesting comments! I knew that there would be a lot of strong reactions to this article – some people would love it and others… well not so much. Either way, thanks for reading (even if it was a little long).

    Just to clarify, the post was not inspired by any inhaled smoke or other mind altering substance (except perhaps my own imagination). Just not into that sort of thing. I am a creative writer myself, and have tried my hand a bit of poetry in the past. I’m also a bit of a theory head and lover of philosophy, so this kind of thing was right up my alley!


↑ Back to top