HTML5 Verification: Simplify the code and improve the quality of the web page
Key Points
- HTML5 verification focuses more on the correct use of elements, the accuracy of attribute values ??and the integrity of required attributes, rather than the code style. It is still a valuable tool to ensure that your tags comply with HTML5 specifications.
- There are many differences between XHTML and HTML5 validation, including optional elements and attributes, case insensitivity, and the effectiveness of previously deprecated elements. It is recommended that you choose a style and maintain consistency throughout your HTML5 project.
- HTML5 verification is critical to ensuring that web pages are correctly formatted and interpreted by the browser, thereby improving performance, reducing errors and improving accessibility. There are a variety of online and offline tools available for HTML5 verification, and stricter verification tools are available for those who wish to adhere to stricter guidelines.
(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.
- Empty elements (i.e. elements without corresponding closed tags or without anything) do not need to be closed with closed slashes; for example meta and br.
- Elements and attributes can be uppercase, lowercase, or mixed case.
- No quotation marks are required around the attribute value. The exception is to use multiple space-separated values, or the URL appears as a value and contains a query string with an equal sign (=) character.
- In XHTML-based syntax, some properties that are required in XHTML are no longer required in HTML5. For example, the type attribute of the script element and the xmlns attribute of the html element.
- Some elements that are deprecated in XHTML and therefore invalid are now valid; one example is the embed element.
- Straight text that does not appear in any element but is placed directly in the body element will invalidate the XHTML document; this is not the case with HTML5.
- Some elements that must be closed in XHTML can not be closed in HTML5 without causing validation errors; such as p, li, and dt.
- form element does not require an action attribute.
- The form element (e.g. input) can be used as a direct child of the form element; in XHTML another element (e.g. fieldset or div) is needed to wrap the form element.
- textarea elements do not require rows and cols attributes. The target attribute of the link is previously deprecated in XHTML. It is now valid in HTML5.
- As discussed earlier in this chapter, block-level elements can be placed within the link (a) element.
- If the & character (&) appears as text on the page, it does not need to be encoded as &.
Note: Stricter verification tools
If you want to use stricter guidelines to verify the grammatical style of tags, there are some tools you can use to help you. One of the tools is Philip Walton's HTML Inspector. To use it, you can include the script in your page during the development phase, then open the browser's JavaScript console in the developer tools and run the command HTMLInspector.inspect(). This will directly display many warnings and suggestions in the console, explaining how to improve your markup. HTML Inspector also allows you to change configurations to customize tools according to your needs.
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)
What is HTML5 verification and why it is important?
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.
How to verify my HTML5 document?
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.
What is the least valid HTML5 document?
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.
What are some common HTML5 verification errors?
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.
How to fix HTML5 verification errors?
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.
What is the role of document type declaration in HTML5 verification?
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.
Can I verify HTML5 documentation that contains CSS and JavaScript?
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.
What are the advantages of using HTML5 validators?
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.
Can I verify HTML5 documents offline?
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.
What is the difference between HTML5 verification and HTML5 consistency checking?
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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

There are three ways to selectively include CSS on a specific page: 1. Inline CSS, suitable for pages that are not frequently accessed or require unique styles; 2. Load external CSS files using JavaScript conditions, suitable for situations where flexibility is required; 3. Containment on the server side, suitable for scenarios using server-side languages. This approach can optimize website performance and maintainability, but requires balance of modularity and performance.

CSS blocks page rendering because browsers view inline and external CSS as key resources by default, especially with imported stylesheets, header large amounts of inline CSS, and unoptimized media query styles. 1. Extract critical CSS and embed it into HTML; 2. Delay loading non-critical CSS through JavaScript; 3. Use media attributes to optimize loading such as print styles; 4. Compress and merge CSS to reduce requests. It is recommended to use tools to extract key CSS, combine rel="preload" asynchronous loading, and use media delayed loading reasonably to avoid excessive splitting and complex script control.

In the following tutorial, I will show you how to create Lottie animations in Figma. We'll use two colorful designs to exmplify how you can animate in Figma, and then I'll show you how to go from Figma to Lottie animations. All you need is a free Fig

We put it to the test and it turns out Sass can replace JavaScript, at least when it comes to low-level logic and puzzle behavior. With nothing but maps, mixins, functions, and a whole lot of math, we managed to bring our Tangram puzzle to life, no J

ThebestapproachforCSSdependsontheproject'sspecificneeds.Forlargerprojects,externalCSSisbetterduetomaintainabilityandreusability;forsmallerprojectsorsingle-pageapplications,internalCSSmightbemoresuitable.It'scrucialtobalanceprojectsize,performanceneed

No,CSSdoesnothavetobeinlowercase.However,usinglowercaseisrecommendedfor:1)Consistencyandreadability,2)Avoidingerrorsinrelatedtechnologies,3)Potentialperformancebenefits,and4)Improvedcollaborationwithinteams.

CSSCounters is a tool for creating automatic numbers. 1. Basic usage: define and operate counters through counter-reset and counter-increment, such as "SectionX." before h2. 2. Advanced usage: Use nested counters to create complex numbers, such as chapter and section numbers. 3. Notes: Ensure the counter is reset correctly, optimize performance, and simplify counter logic. 4. Best practice: clear naming, define counters in CSS, and use counter-increment and counter-reset reasonably.

CSSismostlycase-insensitive,butURLsandfontfamilynamesarecase-sensitive.1)Propertiesandvalueslikecolor:red;arenotcase-sensitive.2)URLsmustmatchtheserver'scase,e.g.,/images/Logo.png.3)Fontfamilynameslike'OpenSans'mustbeexact.
