Troubleshooting Common 'style amp-custom' CSS Errors in AMP
Content
If you've received a notification from Google Search Console about a CSS syntax error in tag 'style amp-custom', you're not alone. This is one of the most frequent issues users encounter when implementing AMP on their WordPress sites. This guide will explain what this error means, why it happens, and provide the most common solutions to resolve it.
What is the 'style amp-custom' Tag?
AMP has strict rules for CSS. All custom styles for a page must be consolidated into a single <style amp-custom> tag placed in the <head> of the document. The AMP plugin for WordPress handles this process automatically, but problems can arise from other sources.
Why Do These CSS Errors Occur?
The error indicates that the CSS contained within the <style amp-custom> tag does not follow proper CSS syntax rules. This is almost never caused by the AMP plugin itself. Instead, it is typically due to invalid CSS code generated by your active theme or another plugin on your site. The AMP plugin collects all this CSS, and if the source contains an error, the entire amp-custom block becomes invalid.
Common Solutions to Fix 'style amp-custom' Errors
1. Identify the Source of the Invalid CSS
The first step is to find which theme or plugin is generating the broken CSS. You can use the AMP Validator tool. Paste your AMP URL into the validator and look at the detailed results. It will often point to the specific line of malformed CSS.
Example from the threads: One user's error was traced to this invalid CSS from a table plugin:
.tablepress>:where(thead { ... }
The correct syntax should use :is instead of :where in this context.
2. Check for Common CSS Culprits
Based on the sample threads, here are some specific things to look for:
- Malformed Media Queries: Ensure all
@mediarules are properly closed. One instance showed@media none{h1,h2,h3,h4,h6{overflow-wrap:break-word}which was missing a closing bracket. - Broken URLs: Check for incorrect
url()declarations in your CSS, such as unterminated strings or missing parentheses. - Unsupported Selectors: Some newer CSS selectors might not be fully supported or could be written with incorrect syntax.
- CSS from Page Builders: Themes like Divi and other page builders can sometimes output very large or complex CSS that may contain errors.
3. Use the AMP Developer Tool
You can enable the AMP developer tool to help pinpoint validation issues. To enable it, go to your WordPress dashboard and navigate to AMP > Settings > Other. Check the box for "Enable Developer Tools." Once enabled, you can view your AMP pages and see validation warnings directly in your browser's console, which can make tracking down the problematic CSS much easier.
4. Conflict Testing
If you cannot easily find the invalid CSS, a standard troubleshooting step is to test for conflicts.
- Switch temporarily to a default WordPress theme (like Twenty Twenty-Four).
- Disable all plugins except AMP.
- Check if the validation error disappears.
- If it does, reactivate your theme and plugins one by one, checking the validator after each, until you find which one causes the error to return.
5. Exceeding the CSS Byte Limit
Another related error is tag 'style amp-custom' is too long - the limit is 75000 bytes. The AMP plugin performs "CSS tree shaking" to remove unused styles, but if your theme and plugins add excessive CSS, you may exceed this hard limit. The solution is to identify and reduce the amount of CSS, often by finding a more lightweight theme or disabling plugins that add large amounts of style code.
When to Seek Further Help
If the error is traced to a specific third-party plugin or theme (like 'Ezoic', 'TablePress', or a specific page builder), you will need to contact that product's support team for assistance, as they are best equipped to fix the CSS output by their software. The 'AMP' team cannot modify code from other developers.
Remember, while these warnings should be addressed, a CSS syntax warning may not always break the visual display of your page. However, resolving them is important for maintaining valid AMP pages in Google Search Console.
Related Support Threads Support
-
Tag found outside the document headhttps://wordpress.org/support/topic/tag-found-outside-the-document-head-2/
-
after instaling AMP plugin i got many errors in google search consolehttps://wordpress.org/support/topic/after-instaling-amp-plugin-i-got-many-errors-in-google-search-console/
-
Tag contains text, which is disallowed.https://wordpress.org/support/topic/tag-contains-text-which-is-disallowed/
-
CSS syntax error in tag ‘style amp-custom’.https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-21/
-
The mandatory attribute ‘amp-custom’ is missing in tag ‘style amp-custom’.https://wordpress.org/support/topic/the-mandatory-attribute-amp-custom-is-missing-in-tag-style-amp-custom-3/
-
CSS syntax error in tag ‘style amp-custom’.https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-26/
-
Confused by message saying AMP issue detected on my sitehttps://wordpress.org/support/topic/confused-by-message-saying-amp-issue-detected-on-my-site/
-
CSS syntax error in tag ‘style amp-custom’https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-23/
-
Error in the “style amp-custom” taghttps://wordpress.org/support/topic/error-in-the-style-amp-custom-tag/
-
CSS syntax error in tag ‘style amp-custom’.https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-30/
-
Tag ‘html’ marked with attribute ‘data-ampdevmode’.https://wordpress.org/support/topic/tag-html-marked-with-attribute-data-ampdevmode/
-
CSS syntax error in tag ‘style amp-custom’.https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-24/
-
AMP Plugin says AMP Pages are valid but Google Search Console Says they are not.https://wordpress.org/support/topic/amp-plugin-says-amp-pages-are-valid-but-google-search-console-says-they-are-not/
-
search console errorhttps://wordpress.org/support/topic/search-console-error-12/
-
script tag is present more then in the documenthttps://wordpress.org/support/topic/script-tag-is-present-more-then-in-the-document/
-
CSS Syntax error in tag style AMP Custom in AMP Pageshttps://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-in-amp-pages/
-
GSC reports a warning for style amp-customhttps://wordpress.org/support/topic/gsc-reports-a-warning-for-style-amp-custom/
-
CSS syntax error in tag ‘style amp-custom’ – bad url.https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-bad-url-2/
-
CSS syntax error in tag ‘style amp-custom’.https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-22/
-
CSS syntax error in tag ‘style amp-custom’.https://wordpress.org/support/topic/css-syntax-error-in-tag-style-amp-custom-28/
-
tag ‘style amp-custom’ is too long – the limit is 75000 byteshttps://wordpress.org/support/topic/tag-style-amp-custom-is-too-long-the-limit-is-75000-bytes/