How can I add a class to a link output via a form? Based on this answer, I'm attempting to add a cancel link.  By default, however, the following code just displays a plain link with no ids and classes.

  if(arg(1) == 'add') {
    // If adding node link to node/add screen
    $link = l(t('Cancel'), 'node/add');
  }
  elseif(arg(2) == 'edit') {
    // If editing node, link to node view screen
    $link = l(t('Cancel'), 'node/'.arg(1));
  }
  $form['cancel'] = array(
    '#type' =&gt; 'markup',
    '#value' =&gt; $link,
    '#weight' =&gt; 0,
  );


How can I add arbitrary css classes and an id to the link that is output?
Take a look at the l() function:

l(t('link_text'), 'path', array('attributes' =&gt; array('class' =&gt; array('your_class'), 'id' =&gt; 'your_id')));