0

Publishing an ebook, and the Kindle validation (in Kindle Previewer 3) fails because the conversion software adds a "class" attribute to the <html> tag.

The style only sets margins and padding to 0, which surely could be as easily done by redefining the html tag.

a) would it be safe to remove the attribute, and b) was it even necessary in the first place?

(I realise the answer should be very simple to find, but searching Google for the terms html, class, tag etc is only ever going to give me generic pages on writing html or CSS :(

<html xmlns="http://www.w3.org/1999/xhtml" class="calibre">

where .calibre { margin:0; padding:0;}

I would prefer <html xmlns="http://www.w3.org/1999/xhtml">

where html { margin:0; padding:0;}

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
mattyniner
  • 11
  • 2
  • There is no harm in having a class on `` tag. And especially with the usage of frameworks, it is common practice. – tacoshy Jun 19 '23 at 07:43
  • “ a) would it be safe to remove the attribute” — Have you tried? – Quentin Jun 19 '23 at 07:48
  • “b) was it even necessary in the first place?” — Depends on context – Quentin Jun 19 '23 at 07:48
  • @tacoshy, I realise it's not normally a problem, and html does allow for it, BUT, the specific situation makes it undesirable i.e. Amazon will not accept the book to publish with what it sees as errors. – mattyniner Jun 20 '23 at 11:09
  • @Quentin, I have removed it, and it compiles the ebook without issue. The draft is accepted by Kindle Previewer. I was really just worried about it affecting the layout when published, and I get the impression from the answers that I can pretty much either leave it out, or shift the attributes to the html tag. – mattyniner Jun 20 '23 at 11:09

2 Answers2

-3

try to use class attribute in body tag it work similar

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 19 '23 at 15:01
  • thanks, but I was trying to avoid unnecessary "class" attributes when I know how touchy the validator can be! – mattyniner Jun 20 '23 at 11:10
-4

You know, the "class" attribute in the <html> tag is like a fancy hat at a casual picnic. It's not necessary, but doesnt hurt either. Browsers don't care about it, and the HTML specification doesn't either.

It's like a quirky addition from the Kindle conversion software that tries to impose its default styles on your document.

Here's a simplified HTML code that will work just fine without that "class" attribute:

If you want to apply some default styles, You can easily do that with the tag itself, this will achieve the same result as the "class" attribute:

html {
  margin: 0;
  padding: 0;
}
Martijn
  • 15,791
  • 4
  • 36
  • 68
peterdsp
  • 29
  • 4
  • “ Browsers don't care about it, and the HTML specification doesn't either.” is just plain wrong. – Quentin Jun 19 '23 at 07:46
  • 1
    I've editted the "spiffyness" oout of the answer (trying to keep the intent). Here at SO we dont mind a little humor, but 'a little' is key there. Factual, 'explaining' answers have the preference, not funny ones. Not a downvoter, but wanted to leave a little feedback :) – Martijn Jun 19 '23 at 07:47
  • “If you want to apply some default styles, You can easily do that with the tag itself, this will achieve the same result as the "class" attribute” — Did you copy/paste the code there straight out of the question? – Quentin Jun 19 '23 at 07:47
  • @Quentin I was wrong to say that browsers and the HTML specification don't care about the class attribute in the tag. The HTML specification does indeed allow for a class attribute on the tag, and some browsers do use it to apply default styles to the document. However, I still believe that it is not necessary to use the class attribute on the tag. The default styles that are applied by browsers are usually fine, and if you need to apply custom styles, you can do so in your CSS file. – peterdsp Jun 19 '23 at 07:49
  • one thing more to add: `specificity weight`... – tacoshy Jun 19 '23 at 08:00
  • Thx Peter - I figured that would have the same effect. Just seeing if anyone with kindle/calibre experience would warn me off my preferred course! With no one saying that this will break my kindle reader, haha, I feel safe enough to make the changes. Knowing how css works is one thing, but trying to apply that to an unfamiliar tech parsing it... – mattyniner Jun 20 '23 at 11:28