An AMP Invalid URLerror occurs when a URL used on an AMP (Accelerated Mobile Pages) page does not meet AMP's URL and HTML validation requirements.
One of the common errors reported in Google Search Console is:
Invalid URL protocol in attribute
hrefof taga
This error indicates that an <a> tag on the AMP page contains a URL with an unsupported protocol or an incorrectly formatted URL.
Why Does an AMP Invalid URL Error Occur?
AMP pages follow specific URL and HTML validation rules. An invalid URL error can occur when an AMP page contains:
- An unsupported URL protocol, such as javascript:
- A malformed or incorrectly formatted URL
- A URL generated incorrectly by the CMS or publishing system
- A link inserted by a third-party widget, tool, or integration
- AMP-incompatible HTML within the page content
Example:
An AMP page may contain a link such as: <a href="javascript:void(0)">Read More</a>
The javascript: protocol is not permitted in AMP. As a result, Google Search Console may report:
Invalid URL protocol in attribute href of tag a
If the link is intended to navigate to another page, it should use a valid URL instead:
<a href="https://example.com/article">Read More</a>
If the link is intended to perform an action rather than navigate to another page, use an AMP-supported implementation instead of a JavaScript URL.
Common AMP Validation Errors
The following table lists some common AMP validation errors and the recommended actions to resolve them:
| AMP Validation Error | Recommended Action |
Missing ⚡ (amp) attribute in the <html> tag |
Ensure the AMP page includes the required AMP declaration. |
| Missing or incorrect AMP runtime scripts | Ensure the required AMP runtime and component scripts are included in the <head>. |
Missing amp-custom attribute on <style> tags |
Place custom CSS inside the required <style amp-custom> block. |
AMP scripts rendered inside the <body>
|
Move AMP runtime and component scripts to the <head>. |
| Unsupported HTML attributes | Remove unsupported attributes or replace them with AMP-compatible alternatives. |
| Empty or invalid attribute values | Remove invalid values or replace them with valid values. |
| Custom JavaScript | Remove custom JavaScript or replace it with supported AMP components. |
| Standard HTML elements instead of AMP components | Replace elements such as <img> with the appropriate AMP components, such as <amp-img>. |
Inline styles or multiple <style> tags |
Consolidate custom styling into the <style amp-custom> block. |
| Invalid HTML copied from external sources | Clean the HTML to remove unsupported tags and attributes before publishing. |
| Unsupported third-party widgets or embeds | Replace them with AMP-supported components or remove them from the AMP version. |
| Invalid or unsupported HTML tags | Remove unsupported tags or replace them with AMP-compatible alternatives. |
How to Identify and Fix AMP Validation Errors
1. Identify the affected AMP pages
Check the affected URLs listed in Google Search Console and open the corresponding AMP pages. Review the specific validation error reported for each URL to understand what needs to be corrected.
2. Check the page content and links
Review the HTML and content on the affected AMP page, particularly the href values of links.
Look for:
- Unsupported URL protocols such as javascript:
- Invalid or incomplete URLs
- Incorrect URL formatting
- Unsupported HTML attributes
- Custom JavaScript
- Third-party widgets or embeds that may not be AMP-compatible
3. Correct the identified issues
Depending on the validation error, correct, replace, or remove the invalid HTML or URLs.
For example, replace unsupported JavaScript URLs with valid URLs where the link is intended to navigate to another page.
If the issue is caused by unsupported HTML or attributes, replace them with AMP-compatible alternatives.
4. Check the source of the issue
If the same validation error appears across multiple pages, check whether the issue is being introduced through:
- CMS content
- Story templates
- AMP templates
- Custom HTML
- Third-party widgets or integrations
Addressing the issue at its source can help prevent the same validation error from occurring on additional pages.
5. Validate the updated AMP page
After making the required changes, validate the affected page using an AMP validation tool to confirm that it complies with AMP requirements.
You can use the AMP Validator to identify any remaining validation issues.
If the Error Affects Multiple Pages
If the same AMP validation error is reported across a large number of URLs, avoid correcting each URL individually without first identifying the common source.
A recurring error across multiple URLs may indicate an issue with the CMS configuration, AMP template, story content, or a third-party integration.
Identifying and correcting the underlying source can resolve the issue more efficiently and help prevent it from recurring.
Best Practices
To minimize AMP validation issues:
- Use valid and supported URL formats in page content.
- Avoid JavaScript URLs such as javascript:void(0) in AMP pages.
- Use AMP-supported components instead of unsupported HTML or JavaScript.
- Review custom HTML and third-party integrations for AMP compatibility.
- Validate AMP pages after making changes to templates or content.
- If the same validation error occurs across multiple pages, investigate the common source rather than correcting URLs individually.
Related Resources
For more information about AMP validation requirements and supported HTML elements, refer to the official AMP documentation: AMP HTML Specification
Once the relevant issues have been corrected, the affected URLs can be revalidated in Google Search Console to confirm whether the AMP validation errors have been resolved.