Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xhtml self-closing anchor element <a /> allowed?

Tags:

html

css

xhtml

If I make an anchor element and don't want text within it, because I'm gonna to css-i-fy it with a nice image and a hover-effect... I wonder if it is legal to write <a id="hoverimage" href="google.com" /> validome.org & validator.w3.org say YES ?

BTW: anyone knows an equivalent to alt element for this case?

like image 820
iceteea Avatar asked Nov 09 '11 11:11

iceteea


People also ask

How do you close a tag in XHTML?

XHTML tags must be closed with a closing tag or a trailing slash. Examples: <p>Some text</p>, <br />. In HTML, closing tags and trailing slashes are not required (but they are acceptable). XHTML does not permit overlapping nested tag structures.

Which HTML elements can be self closing?

Some few self-closing tags are <input/>, <hr/>, <br/>, <img/>, etc. Self-closing tags in html are sometimes also known as empty tags, void tags, singletons tags, etc. This means that these tags have no content and cannot have any children.

Does anchor tag have a closing tag?

An anchor is a piece of text which marks the beginning and/or the end of a hypertext link. The text between the opening tag and the closing tag is either the start or destination (or both) of a link. Attributes of the anchor tag are as follows. OPTIONAL.

How do you make a self closing link element?

A self-closing tag is an element of HTML code that has evolved in the language. Typically, the self-closing tag makes use of a “/” character in order to effectively close out a beginning tag enclosed in sideways carets.


1 Answers

It is valid in XHTML. It is not HTML-Compatible so likely to break in a document served as text/html. Having a link with no content is bad practise (background images are not content (which is why there is no equivalent to the alt attribute)).

like image 66
Quentin Avatar answered Sep 22 '22 23:09

Quentin