Home >Web Front-end >CSS Tutorial >Validating HTML5 Documents - SitePoint
HTML5 Verification: Simplify the code and improve the quality of the web page
Key Points
(The following is excerpted from the book "HTML5 & CSS3 for the Real World, 2nd Edition" co-authored by Alexis Goldstein, Louis Lazaris and Estelle Weyl. The book is available in stores around the world, and you can also find it here. Purchase the e-book version. )
In the previous chapter, we introduced some syntax changes in HTML5 and touched on some validation-related issues. Let's expand these concepts in more detail so that you can better understand the changes in how pages are validated.
HTML5 validator no longer focuses on code style. You can use uppercase or lowercase letters, omit quotes in attributes, exclude optional closed tags, and you can be arbitrarily inconsistent, your page will still be valid.
Then, you might ask, what is considered an HTML5 validator error? It will remind you of wrong use of elements, elements that should not be included, missing required attributes, wrong attribute values, and more. In short, the validator will let you know if your tags conflict with the specification, so it is still a valuable tool when developing a page.
To give you an idea of how HTML5 differs from overly strict XHTML, let's look at some details. This way you can understand what is considered valid in HTML5:
In XHTML-based syntax, some elements that are required in XHTML are no longer required in HTML5 to enable the document to pass HTML5; such as html and body elements. This is because even if you exclude them, the browser will automatically include them in the document.
Note: Stricter verification tools
Summary
So far, we have learned about almost all the new semantic and syntax changes in HTML5. Some of this information may be difficult to digest at first, but don't worry! The best way to get familiar with HTML5 is to use it – start with your next project. Try using some of the structural elements we introduced in the previous chapter, or some of the text-level semantics we saw in this chapter. If you are not sure what an element is for, go back and read about that section, or, better yet, read the specification itself. While the language is certainly more boring than the text in this book (at least we hope so!), the specification can more fully describe the intended use of a given element. Remember that the HTML5 specification is still under development, so some of the content we've covered can still happen in the new HTML5.1 version (or in the HTML5 "dynamic standard" if you follow the definition of WHATWG) change. The specification will always contain the latest information.
In the next chapter, we will look at the key new features introduced in HTML5: forms and form-related features.
HTML5 Document Verification FAQ (FAQ)
HTML5 verification is a process of checking web page code according to the formal syntax rules of the HTML5 specification. This is very important because it ensures that your web page is formatted correctly and can be interpreted correctly by the browser. This will lead to better performance, fewer errors, and improved accessibility for users with disabilities. Additionally, it can help with SEO, as search engines prefer well-structured and error-free sites.
You can use online tools such as W3C tag verification services to verify your HTML5 documents. Simply enter your webpage URL or upload your HTML file and the tool will check it against the HTML5 standard and report any errors or warnings.
The minimum valid HTML5 document is the simplest HTML5 document, which still complies with the standards set by the HTML5 specification. It includes document type declaration, root element (html), head element and body element.
Common HTML5 validation errors include missing closed tags, incorrect nesting of elements, use of deprecated elements or attributes, and forgetting to include document type declarations at the beginning of the document.
Fix HTML5 verification errors include correcting code based on error messages provided by the verification tool. This may include adding missing tags, deleting or replacing deprecated elements, or correcting nesting of elements.
Document type declaration is the first line of an HTML5 document, which tells the browser which version of HTML is written in. It is crucial for verification because it helps the browser and verification tools interpret the rest of the code correctly.
Yes, you can verify HTML5 documents that contain CSS and JavaScript. However, verification only checks the HTML code. For CSS and JavaScript, you need to use a separate verification tool.
Using HTML5 validator can help you catch and fix errors before they cause problems. It can improve your website's performance, accessibility, and search engine rankings. It is also a great way to learn more about HTML and improve your coding skills.
Yes, there are tools that allow you to verify HTML5 documents offline. These tools include software applications and command-line tools that you can install on your computer.
HTML5 validation is about checking the syntax of code according to HTML5 specification. Consistency checking, on the other hand, is about making sure your web pages follow best practices in web design and accessibility, and syntax correct.
The above is the detailed content of Validating HTML5 Documents - SitePoint. For more information, please follow other related articles on the PHP Chinese website!