How-To Use Valid XHTML Tags in TextMate


How-To Use Valid XHTML Tags in TextMate

Here’s a tip I just now found out about. In TextMate, the HTML bundle has a ton of available snippets. Unfortunately, they don’t automatically add the closing trailing slash for certain elements. For example, instead of inserting

<br/> or <input type="text"/>

TextMate inserts

<br> or <input type="text">

(Note the missing trailing slashes.)

You can change this behavior by going to

  1. TextMate Preferences → Advaned → Shell Variables
  2. Create a new variable called “TM_XHTML” with value “/” (no quotes)

Now TextMate will output valid XHTML when you use the HTML bundle.

Related Posts Plugin for WordPress, Blogger...

Tell us what you think

  • Tom Bates

    Great tip, thanks :)

    I might recommend adding a space before the slash in the value field, as the XHTML spec indicates that this is necessary; so becomes

  • luke hartman

    mike, this isn’t set by default because, for reasons I can’t explain, there are people out there still using HTML.

    Thanks for this tip. TextMate’s built-in validator is much happier now :-)

  • mike

    … and why isn’t this set by default?

  • Pix

    is that all?
    i’m new about mac and textmate and i was just wondering why it doesnt close single tags!

    i don’t really know what i’ve just done but seems works!


  • erat

    Oh, for cryin’ out loud… THAT’S how you do it.

    The missing slash has been driving me nuts!