Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have attributes on closing tags?

Tags:

html

There are many people that mark closing tags like this to help identify the closing tag that goes with an HTML tag:

<div id="header">   <div id="logo">     <a href="index.php">       <img id="logoimg" src="images/as_logo.png" alt="Logo" border="0" />     </a>   </div> <!-- logo --> </div> <!-- header --> 

I was wondering if it is syntactically ok to do this:

<div id="header">   <div id="logo">     <a href="index.php">       <img id="logoimg" src="images/as_logo.png" alt="Logo" border="0" />     </a>   </div id="logo"> </div id="header"> 

UPDATE: Here is the text from the spec on HTML5.3:

8.1.2.2. End tags
End tags must have the following format:

  1. The first character of an end tag must be a U+003C LESS-THAN SIGN character (<).
  2. The second character of an end tag must be a U+002F SOLIDUS character (/).
  3. The next few characters of an end tag must be the element’s tag name.
  4. After the tag name, there may be one or more space characters.
  5. Finally, end tags must be closed by a U+003E GREATER-THAN SIGN character (>).

8.1.2.3. Attributes
Attributes for an element are expressed inside the element’s start tag.

Note that attributes are only allowed on START TAGS.

using @jbyrds idea; using the HR tag allows you to see if you forgot the z attribute:

<div id="header">   <div id="logo">     <a href="index.php" id=link">       <img id="logoimg" src="images/as_logo.png" alt="Logo" border="0" />     </a><hr z="link">   </div><hr z="logo"> </div><hr z="header"> 

Although this adds more text, 32 extra characters vs. the original or the tags having a hidden class, you can use CSS to hide them.

[z] {     display: none; } 
like image 878
MB34 Avatar asked Nov 09 '10 20:11

MB34


People also ask

Can attributes be added to the opening and closing tag of an HTML element?

Attribute Name and Values HTML attributes consist of a name and a value using the following syntax: name="value" and can be added to the opening tag of an HTML element to configure or change the behavior of the element.

Can tags have attributes?

Tags can also have attributes, which are extra bits of information. Attributes appear inside the opening tag and their values sit inside quotation marks.

What character is needed for the closing tag?

The '/' (forward slash) is used to represent the closing of a tag in HTML.

Do attributes always go in the opening tag?

HTML attributes generally come in name-value pairs, and always go in the opening tag of an element.


2 Answers

Short answer, No.

Use the comments instead.

like image 60
Marko Avatar answered Oct 03 '22 01:10

Marko


The answer is no for most tags. However, you could argue that tags like "img" that can be self-closing, are able to have attributes in them. But these self-closing tags are taking the place of an opening tag and a closing tag, so it's not the same as having an attribute in a closing tag. To be honest, there is really no need for this, it would just create more for the browser to have to read and make the page size bigger.

like image 32
Blake Avatar answered Oct 03 '22 01:10

Blake