Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it OK to style the <html> tag?

Sometimes you want two body backgrounds. One for the header and one for the footer. I accidentally discovered that it is possible to style the actual <html> tag.

HTML:

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

CSS:

html {background:#000}

Is it OK to style this, or will it cause any problem?

like image 881
Hakan Avatar asked Apr 08 '11 04:04

Hakan


People also ask

Should you style html tag?

The HTML tag style is useful for any website In the end, this will make it easier for you to build a website in a neat and well-structured way. If you also want to use external CSS files, use the link tag for that.

Can I use style in HTML?

The style attribute is part of the Global Attributes, and can be used on any HTML element.

Can we give style to a tag?

The <style> tag is used to define style information (CSS) for a document. Inside the <style> element you specify how HTML elements should render in a browser.

Should you style body tag?

Any styling you want to do on the <body> should be put into your CSS. And, in fact, <body> is a great place to put all the CSS that should affect the document display as a whole: things like fonts and typography, text and background colors, and other other “default” styling.


3 Answers

Yes, it's OK to style the html tag.

like image 143
Phrogz Avatar answered Sep 28 '22 07:09

Phrogz


Although it's debatable as to whether it's valid [see here]:

For HTML documents, however, we recommend that authors specify the background for the BODY element rather than the HTML element. ...

Many large sites still use it with seemingly consistent results.

like image 27
Dave Avatar answered Sep 28 '22 07:09

Dave


It is very common practice. Used all the time on many websites including this one.

like image 45
Craig White Avatar answered Sep 28 '22 08:09

Craig White