Forum Moderators: Robert Charlton & goodroi

Message Too Old, No Replies

Canonical Tags in HTML5 - Is a Closing "/" Necessary?

         

cdblaine

3:27 am on Feb 24, 2019 (gmt 0)

5+ Year Member



Hello,

In one tutorial on proper use of canonical tags I saw this as an example, which contains a closing "/".

<!DOCTYPE html>
<html>
<head>
<link rel="canonical" href="https://example.com/page.html" />
</head>

But I've also seen numerous instances in which the "/" is omitted.
Is the closing "/" optional?

Thank you.

phranque

3:16 am on Feb 25, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld [webmasterworld.com], cdblaine!

as far as html5 is concerned (i.e. <!DOCTYPE html>):
the <link> element is a "void element".
Void elements only have a start tag; end tags must not be specified for void elements.

source: https://www.w3.org/TR/html52/syntax.html#void-elements

if this were xhtml:
Empty Elements

Include a space before the trailing / and > of empty elements, e.g. <br />, <hr /> and <img src="karen.jpg" alt="Karen" />.

source: https://www.w3.org/TR/xhtml1/#C_2

In one tutorial on proper use of canonical tags I saw this as an example, which contains a closing "/".

this example is marked up using xhtml.

But I've also seen numerous instances in which the "/" is omitted.

these examples are marked up using html5.

Is the closing "/" optional?

no - it is required in xhtml and is non-conforming in html5 but shouldn't cause a syntax error.

cdblaine

5:38 am on Feb 25, 2019 (gmt 0)

5+ Year Member



Thank you, phranque, for your explanation.

When I viewed your reply I saw "Votes: 1". I hadn't done anything, so I wonder how that got there.
I then clicked the Vote icon, so I could add one to the total. But I got a message - You must be logged in to vote.
But I AM logged in. Very confusing.

In any case, thank you.

phranque

6:56 am on Feb 25, 2019 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



if the reply says "Unlike Votes: 1" (with the "Unlike" underlined and linked) you have voted.
if it says "Like Votes: 1" the vote was someone else's vote.