0

Using angular directive, I often have to write tags as follows:

<div ng-custom-directive-attr="xxxx"></div>
<span ng-custom-directive-attr="xxxx"></span>

Is it OK to write them as follows?:

<div ng-custom-directive-attr="xxxx"/>
<span ng-custom-directive-attr="xxxx"/>

If yes, do all major browsers comply with that?

As a side note, one usually write <img/>, and I never saw <img></img> (or seldom seen).

Stéphane de Luca
  • 12,745
  • 9
  • 57
  • 95

1 Answers1

1

There may be browsers that support it (though I doubt that), but it's definitely not valid markup.

If you run this through the W3 Validator, it is not happy.

Input

<!DOCTYPE html>
<html>
    <head>
        <title>blah</title>
    </head>
    <body>
        <div ng-custom-directive-attr="xxxx"/>
        <span ng-custom-directive-attr="xxxx"/>
    </body>
</html>

Output:

W3 Validator output when fed the code above.

ThatDarnPat
  • 80
  • 1
  • 7