Valid HTML
- HTML is a specific list of tags that you are allowed to use.
- Tags have specific attributes that they are allowed to include.
- Some tags are only allowed to have certain tags as children and other tags are only allowed to be inside specific ones.
A common example is with list elements. Inside a <ol>
or a <ul>
the first child element MUST be an <li>
tag. Nothing else is allowed here.
Validation Tools
Many IDEs like VSCode have some validation built-in. They will correct some mistakes that you make. However, not all the validation issues can or will be corrected instantly.
To test your HTML files, try using this tool:
You can copy and paste your HTML into the validator, or upload your file, or provide a URL to the validator. The URL must be an externally visible one. A link that starts with http://localhost/
which points to a location on your own computer will NOT work.
Basic HTML Rules
- All tags need to have a matching closing tag or be self-closing.
- Tags should be written in lower-case
- Tag names never start with a number.
- All attribute values should have double-quotes around their value.
- Ampersands and double quotes should be written as character entities
&
- Comments should be wrapped in
<!-- this is a comment -->
- Self-closing tags can be written with an opening and a closing tag. Eg:
<img></img>
- The first line of every HTML file should be the Doctype declaration.
- The root element of every HTML file is the
<html></html>
element. - All
id
attribute values need to be unique within each page.
More about quotation marks in webpages: