1

Is there any good reason why using <base href="https://example.com/"/> causes structured data testing tool (SDTT) errors to fly from alternate links such as <link rel="alternate" href="this.html"/>?

Simplistic example, try running this through it...should fail:

<!DOCTYPE html>
<html dir="ltr" lang="en">
<base href="https://example.com/" />
<link rel="alternate" href="this.html"/>
</head>
<body>
</body>
</html>

Then running this through it should work (reporting no structured data):

<!DOCTYPE html>
<html dir="ltr" lang="en">
<base>https://example.com/</base>
<link rel="alternate" href="this.html"/>
</head>
<body>
</body>
</html>

Some thoughts: http://www.w3schools.com/tags/tag_base.asp (we use <base />, so its HTML version)

Differences Between HTML and XHTML

  • In HTML the <base> tag has no end tag.

  • In XHTML the <base> tag must be properly closed.

Compared to: http://www.w3schools.com/tags/tag_link.asp which seems to have the paradox logic (as in, all we use is HTML version <link /> with non issue, except when combined with rel="alternate")

Differences Between HTML and XHTML

  • In HTML the <link> tag has no end tag.

  • In XHTML the <link> tag must be properly closed.

Is the use of rel="alternate" that strict and must be XHTML compliant or something?

3
  • What happens if you change /> to > in your HTML tags? Jul 11 '15 at 4:12
  • @Mike Doesn't work that way either (without the slash). It's like one or both of them have to be xhtml [legacy] style for it to not throw error
    – dhaupin
    Jul 13 '15 at 14:23
  • @closetnoc haha thanks. Strange one. Im leaning towards an error in the tool rather than some strange spec quirk
    – dhaupin
    Jul 13 '15 at 14:24
2

Unfortunately, your question didn’t include the errors you saw in the SDTT. Both snippets don’t show any warnings/errors now. So I’m not sure what exactly the issue was, but I want to clear something up in case there is a misunderstanding.

Void elements

The base element is a void element. Void elements don’t have an end tag, and so they can’t have any content.

This is invalid:

<!-- invalid! -->
<base>https://example.com/</base>

This is valid in HTML:

<base href="https://example.com/" />
<base href="https://example.com/">

This is valid in XHTML:

<base href="https://example.com/" />

The same is true for the link element, which is also a void element.

Why your snippet generates data in the SDTT

The SDTT extracts structured data when testing your first snippet (which is valid HTML and XHTML):

Unspecified Type

ID: https://example.com/

  • @type: Unspecified Type
  • @id: https://example.com/
  • http://www.w3.org/1999/xhtml/vocab#alternate:
    • @type: Unspecified Type

(I guess that the SDTT did so in the past, too, but showed errors then.)

The reason it does this is because the rel attribute has a function in RDFa (which is one of the three syntaxes for including structured data supported by SDTT).

In the SDTT, this seems to get triggered when the tested document has a URL (which can be specified with base) and an a/area/link element with a rel attribute defined at https://www.w3.org/1999/xhtml/vocab.

It’s nothing to worry about, just a way how some of the plain HTML semantics can get represented in RDF. When intentionally using RDFa, plain HTML rel values can lead to conflicts, but these can be dealt with.

1
  • Of note: while <base href="https://example.com/" /> is valid in HTML, the closing slash is not specified for the tag itself. It's allowed as a void element but the slash has no meaning, it does nothing, and browsers are instructed to ignore it.
    – Rob
    Nov 19 '18 at 3:23
0

I see one glaring issue: the <!DOCTYPE html> tag is the same in both instances. The top example is the correct formatting except that the DOCTYPE should be

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If you change that, it should work properly.

8
  • This is wrong. No site should be using a transitional doctype since 1999 when sites were transitioning as standards had evolved. All web sites should be using a strict doctype since then.
    – Rob
    Nov 19 '18 at 3:20
  • @Rob W3Schools DOCTYPE page is still showing it as a valid alternative.
    – elbrant
    Nov 25 '18 at 20:47
  • W3Schools, you may need to know, is not affiliated with the W3C in any way, shape or form. What they show is a list of doctypes. Which one that should be used for current HTML web pages is defined in the HTML specification and that is <!DOCTYPE html> and none other. You will find this enlightening and this, too:
    – Rob
    Nov 25 '18 at 23:36
  • @Rob Your 2nd link, from the W3C, supports the "Transitional" DOCTYPE that I listed. The only time it would be appropriate to not use an XHTML DOCTYPE would be if the page included XML code, which would mean that you would need a XML declaration as such '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE...' If you would like to continue the debate, perhaps we should open a chatroom.
    – elbrant
    Nov 26 '18 at 0:36
  • The purpose of the transitional doctype is to "transition" old web sites from the standards before 1999 to those set after 1999. Listing such a doctype does not mean it's OK for you to use it. You aren't using pre-1999 markup. At least I would hope not. It serves no purpose. Read and follow the spec. The browser vendors do. They wrote it. There is nothing to debate here.
    – Rob
    Nov 26 '18 at 1:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.