make sure html_tag() generates compliant HTML. closes #1616

modified due to lack of response of the original PR author.