Jump to content

Attach Styles To Html Element


mattmill30
 Share

Recommended Posts

Hi,Is its standards compliant to attach styles to the html element?Because in a webpage i am using:

<html style="background-color: #000; font-family: trebuchet ms, arial, sans-serif; font-size: 1em">

It renders correctly on firefox and konqueror, however, when I attempted to validate the page using totalvalidator I recieved this error: 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 2 E620 The 'style' attribute is not valid for this tag here: E621 The 'xmlns' attribute for this tag is missing: W864 [WCAG v2 3.1.1 (A)] Use the 'lang' or 'xml:lang' attribute to denote the primary language of the document: <html style="background-color: #000; font-family: trebuchet ms, arial, sans-serif; font-size: 1em">Does using style in the html element comply with the (x)html standard?If not, is styling of the html element supported by the css standard, if i were to do it through css?If styling the html element is supported, then would it be correct to use the following order of code to style the html element, if the styling is applied in the head element, after the html element:

<html>	<head>		<title>Nicholas Hill Studio - Fine Art to Fire your Imagination</title>		<style>		html {		background-color: #000; font-family: trebuchet ms, arial, sans-serif; font-size: 1em		}		</style>	</head></html>

If someone could provide a link to the standard to backup their comments, i'd be greatful.Thanks for any help provided,Matthew Millar

Link to comment
Share on other sites

yes, the recommendation of the W3 is to use CSS.perhaps you are missing this line of code in your head?

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

Edited by thescientist
Link to comment
Share on other sites

There are several issues at work here. The first is priority. Remember that style declarations can override one another. That's the "cascading" part of CSS. A rule of thumb is that the closer a CSS definition is to the element it applies to, the more "force" it has to override previous definitions. External CSS documents have the least force; in-the-tag definitions have the most.That is the only standard you need to worry about. If the standards writers did not intend for inline styles to be used, they would not have provided the mechanism.The rest is best-practice, most of which is not really written down anywhere, but reflects the combined wisdom of experienced developers. So here is some of that.Inline definitions are handy when you have a bunch of class definitions in other style sheets and need to override 1-2 features for a particular element.And inline definitions are often the most expedient practice when documents are generated on the fly using PHP or ASP or a similar pre-processor.Experience tells us that hyper-dependence on inline styles makes documents more difficult to maintain, especially in corporate settings where, over the course of a document's lifetime, multiple authors may contribute to its content, sometimes with time-spans of a year or more falling between each contribution. But even many solo authors find that a document is easier to maintain when they contain very few inline style definitions. Again, the problem is magnified when you look at a page after many weeks and think, "What was I doing here?"Consultants will also have an easier time assisting you if you keep all your style definitions in one place. (I assume you visit boards like this one for a reason; think of us as your underpaid consultants.)Obviously, you are free to make your own choices when it comes to issues of pragmatism. I have simply discussed things for your consideration. Insisting on documentation to backup someone's comments might be appropriate in a context where you are paying for advice. In a context or voluntary assistance, I recommend being grateful for anything that comes your way, documented or not.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...