How to comment on an HTML attribute?

The final (closing) angle bracket in the code below is not interpreted as the closing <input> element:

 <input type='text' name='name' <!-- id='name' -->> 

I thought this was the right way to comment on this attribute, but Google Chrome, Firefox and Notepad ++ (color coding) say that this is not the way to go.

I used CTRL + Shift + Q in Notepad ++ for this.

Then what is the correct way to comment on this <id> attribute?

+6
source share
4 answers

HTML does not allow you to place a comment inside a tag.


If you generate HTML code in a template / programming language, you can use its functions to comment on something.

For example, in the Template-Toolkit:

 <input type='text' name='name' [%# id='name' %]> 

or PHP:

 <input type='text' name='name' <?php # id='name' ?>> 

If you use HTML 5, you can (as an ugly hack) use the data attribute to β€œcomment out” all the attributes.

 <input type='text' name='name' data-comment-id='name'> 
+15
source
 <input type='text' name='name' <?php /* id='name' */ ?> > 

you can use this, it will not be interpreted when viewing the source information

0
source

Usually I just put _x at the end of the attribute name. Then the attribute is ignored because it is unknown. Therefore, if I would like to comment on the id attribute of this element:

 <input type="text" name="name" id="name"> 

I would change it to this:

 <input type="text" name="name" id_x="name"> 

This also has the advantage that you can find " _x= " to find all the commented attributes.

0
source

I agree that you should not use comments in this place. At the same time, the following should work in Chrome, Firefox, and IE:

 <input type="text" %id="test1"% class="test2"> 

Inspect element in Google Chrome

Inspect element in firefox

-2
source

All Articles