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

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

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

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.


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

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

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.


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!



  1. 1
  2. 2

↑ Back to top Tweet itShare on Facebook

Matt is a digital artist who lances freely under the moniker of Echo Enduring Media, and specializes in graphics design, illustration and writing. You can follow Matt on Twitter

  1. 1

    Give me a break. I dig WordPress but they can stuff the whole “code is poetry” bit. Code is poetry just as true as form over function. I don’t write validation scripts thinking to myself, “oh, I hope this regular expression looks pretty and my code looks cute.” When I write a validation script making it look poetic or “flow” is the LAST thing I would ever think of. In fact the only thing I think of while writing a validation script is “this thing is going to keep some sorry ass from scamming my form.”

    Any programmer that approaches code from a “poetic” stand point should STOP CODING. That would be like approaching science from an artistic standpoint. Sorry the world’s problems can’t all be solved by paintbrushes and rainbows. I’m sure somewhere you could squeeze an exception or two in there but for the other %99.99999999 of the time that mode of thinking is what psychologists often refer to as “MAGICAL THINKING”.

    Grow up.

  2. 102

    Your article impacted me profoundly in more ways than one: from my amateurish attempts at coding to life in general…

    This line especially is still resounding in my head like a catchy refrain from a wonderful song:

    “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.”

    You are one very gifted writer.

    I’m a fan.

  3. 203

    I am quite agreen with the write’s says about the experiencial knowledge of better living.For home improvement I have glance those sits.I found they benifit for life. I want to buy something to home see for use. Hope you give me a good views

  4. 304

    Christian Sciberras

    September 15, 2010 4:49 pm

    Hello Matt!

    Very interesting article, one which I agree with to it’s entirety.

    In the last few sentences you posed some interesting questions, which I’d like to reply to.

    First, a little background; I’m no linguist – by far. However, the best I consider myself at, is English (which, alas, is not even my native language – go figure :) ). I’ve developed code for different environments and in different languages. I can say I’ve passed through the pain of, not only seeing bad code, but even having to fix it!

    But back to your question. You asked if someone could bring light on how/why the metaphor seems so realistic.

    As we all know, all computer languages have been evolving, be it due to hardware, software, complexity or simply age. But there’s a pattern to it; each update brings more features which usually mean; writing less code which, however, does more.

    And that is the key to the answer. First of, we can see how simple snippets express so much more than it’s textual equivalent of a poem. Don’t get me wrong at this point; don’t forget that the English does not readily change like code, there is a different in pace. While a piece of C code could be rewritten in PHP, I don’t expect Hamlet translated to Maltese any time soon (and of course, keeping the same structure).

    So we’re seeing a change, the computer seems to [expresses] itself better with just aa [little] of [beautifully] [crafted] code, which will break up even by removal of a simple character.
    I admit I’m not much of a poem-lover, but aren’t poems [short]and [sweet]? To me it seems simply a matter of expression usig a different medium.
    Perhaps “Code is Art” might have been more to the point. But given the current bulk/mess we have in arts, I think Poetry would be much more appropriate.

    Hope my text was as enjoyable (or at least entertaining) as much as I did in enjoy your article Matt.


  5. 405

    Wow! This article was very thorough and well-versed in poetry and coding techniques. I would have liked to see less about poetry and more about best practices in coding, although it was interesting….a tad lengthy?! Thanks!

  6. 506

    I’d just like to mention the separability of concepts here.
    Code as poesy is a delightful metaphor,
    perhaps not as deep as Lear,
    yet thought provoking in its comparison
    is what makes it dear.

    Beauty in code is different and separable, as is beauty in phrase,
    only synonymous if ‘the best words in the best order’ as Coleridge says.

    Beauty in Physics derived from beauty in Math is well known and renowned,
    with analogies to both code and Coleridge’s idea of poetry particularly sound.

    Simplicity, elegance, inevitability and completeness are common to all three,
    useful as guiding principle and giving pure pleasure to thee and me.

  7. 607

    Nice job. I have been coding since 1965. Code has always been poetry to me.

  8. 708

    This exciting reading!!! the article exactly describes my feeling. it is also possible to see similarities between code and musical notation (especially in the case of J.S. Bach). And one of the best pieces of code-poetry is that of the Fast Fourier Transform (FFT) algorithm, highly recommended for bed-time reading :)

  9. 809

    I think, if I may say so, that the author sees not only the results of his work, but also the beauty of the road towards it. He thinks out-of-the-box. Unfortunately most coders stay inside their box. A pity.

  10. 910

    No, dufus. He’s clearly creating “man” *from* “nantucket”. Simples!

  11. 1011
  12. 1112

    I’m curious to find out what blog platform you are using? I’m having some small security issues with my latest blog and I would like to find something more risk-free. Do you have any suggestions?

  13. 1213

    exactly. Code poetry has been talked about but in real code not markup. Talk about code poetry in Smalltalk or in Perl even and it makes sense but not HTML !

  14. 1314

    Love the phrase “Code is Poetry”

    It’s cool to say and think because, Code is Not Poetry.
    So when we think and say it, two worlds collide – which is food for the brain.

    Who doesn’t love a bridge between science and art?

    But getting hired to write poetic CSS? I don’t think so….
    When I’m on a deadline coding CSS for a business/client, the LAST thing anyone wants, is for me to start crafting the CSS similar to how I would craft a poem.. ie. sitting under a tree, no thought of deadlines, writing and erasing and writing, words to fit nicely into a poem, with only a fleeting glimpse here and there of what feels right, hoping to draft a poem that feels like a snowflake of symmetry and individuality…. that’s not what I’m getting paid to do when I write CSS. Sure, I can inject poetic solutions to faster-loading code, but my client did not hire me to spend hours obsessing over a line of code b/c one day another coder will read it and say, wow, what beautiful code. Can you imagine billing for more poetic markup?

    The neat about the phrase “Code is Poetry”, kudos to WordPress for using it as their tagline, is not only the fact that programmers are becoming more and more valuable as creative designers, but I think it gives voice to a movement bubbling under the surface of design/development culture… that voice is really saying is: DON’T FORGET, even in an industrial, scientific craft like markup we can include human individuality, organic-like answers to machine-like rules…

    There was a previous mention of Concrete Poetry in a reply above.. Yes. There was keen movement of “Concrete Poets” in Brasil and Switzerland in the 50’s,
    ….there were a bunch of poets SELF-PUBLISHING, small-press, indie-publishing pamphlets of original poems.. ( like today’s WordPress/blogs, right? “…simple daddy don’t you know that things go in cycles…” -Q-Tip. ) … the main idea for the movement of these poets/musicians/artists, at least as I understand it, was that as Brasil was becoming modern, designing new cities and industrializing in general, Poets were suggesting we keep Poetic sensibilities and check in with “human progress” , what that means…. Unorthodox ideas for example, next to an industrial sign in the street letting you know about a rule, why not also display sign beside it that has a short poem.. a poem that isn’t designed to buy a product, but actually a poem that helps you think for yourself about something poetic and the human condition.

    This movement of poets greatly influenced Brazilian musicicans/artists, as well as in USA’s Art Culture, not only singer songwriters but also I connect the Concrete Poets message to the original graffiti artists in NYC… whether that was a direct influence or not.. graffiti painting “human” elements of colors, non-corporate name-tags, hyper-stylized non-industrial forms painted into and on top of the cold, dull, industrial spaces… (using industrial spray cans, to round out the irony) … that’s poetry jumping out through the codes of industry/commerce.

    The gem inside the phrase “Code is Poetry”, is similar to Concrete Poets of Brasil, OG graffiti artists in NYC.. it’s a reminder: Don’t let “Poetry” (human creativity and sensitivity) die of neglect during an industrial/scientific boom, because “progress” should also include nurturing the fathomless depths of the human spirit.

    All in all, I’ve enjoyed the article and replies, and am game to talk more on this topic.. Ive been working “Code Poem Paintings” , such as ….studying the relationships of code/composition/memory in raga and jazz, so this topic is one of my favorite to explore..

    thanks, Matt for taking the time to write the article, I’m hope I’m not too late in jumping into the conversation…



↑ Back to top