How to Create and Validate Your Own HTML and CSS Templates
When I write an article–or any web page, for that matter–I like to begin with basic HTML, XHTML, and CSS documents I know contain valid code. After reading this tutorial, you will be able to use this approach, too.
There are two types of basic, standards-based documents that I use to write web pages. The first has a Document Type Definition(DTD) of XHTML 1.0 Transitional, just like WordPress uses. The second is a basic HTML document with a Document Type Definition(DTD) of HTML 4.01 Transitional. These definitions tell the browser which specification the document uses. For example, the DTD would be used to tell a browser if the document was HTML or XHTML. The DTD is the first line of code in a web page.
The syntax rules for HTML and XHTML are different in some ways. You must use the correct syntax for the DTD you use or your code will not pass at W3C.This is so even though the browser you use might display your page as expected: browsers are very forgiving with respect to non-standard code.
For the content on my web site, I use the HTML 4.01 Transitional DTD because I am comfortable with its syntax.
The best way to insure that you are starting with a standards-based web page is to first copy a known good skeletal web page and paste it into a basic text editor. Next, save the code as a text file with the “.txt” extension. You could name the file, my-html-template.txt.
You can also paste the code into the W3C Markup Validation Service to check that it is up to snuff: if the code passes the validator “in the green,” you know your code is good. Simple skeletal web pages, can be found at W3 Schools. Other code, such as the DTD for HTML and XHTML, can also be found there.
It is very common to find that online web pages fail W3C validation with a massive number of errors. Sometimes this is because the wrong DTD is specified for a page; at other times, the failure is due to using non-standard or deprecated code. If you start with a valid, basic template and correct any validation errors that show up, your pages will always be “in the green” when they are published to the Web.
Once you have a valid basic template, you can begin to add your content between the body tags and extra code between the head tags.
Normally, I do not use hard carriage returns inside a paragraph. The editors I use all have a “word wrap” feature that enables me to see all the text I write without having to use the horizontal scroll bar. The actual line length of the published content will be determined later when the page display is styled.
I do use a hard carriage return after the last sentence of a paragraph and add an extra one between paragraphs. Hard returns can also be added for extra space between other elements, such as image code.
If you have added content to the my-html-template.txt file, save it again with a “.html” file extension. You can then open it in a browser. What you will see is that all of the content runs together. That is because browsers look for line break tags and not carriage returns. You can fix this by doing a find and replace with your editor: just find every carriage return and replace it with a break tag. When you open the HTML document again, the various parts of the content will be neat and tidy but not very pretty. CSS styling will fix this.
If you are just “dropping” the content between the body tags into a visual editor on the web, such as a WordPress editor or the article content box at EzineArticles, you don’t have to worry about the line breaks as they will be added to the HTML code for you.
Copy and paste the CSS code below into your text editor. Save it as “my-template. css” in the same folder in which you saved your HTML template file.
body
{
background: #fffef2;
color: black;
line-height: normal;
margin: 3% 25% 3% 25%;
min-width: 400px;
}
The link meta tag associates a CSS file with the HTML document. Copy and paste the link tag shown below between the head tags in the my-html-template.txt file you saved. Replace the bracket characters with “”, respectively.
[link title="Template Style Sheet" rel="stylesheet" href="my-template.css"type="text/css"]
If you have added some content to your my-html-template.txt file,