HomeArticleHow to Fix AMP CSS Validation Error Caused by in WordPress 6.7+

How to Fix AMP CSS Validation Error Caused by [sizes=”auto” i] in WordPress 6.7+

Resolve AMP style amp-custom errors in WordPress using safe methods without breaking your theme or site updates

Preferred Source of Google

If you are using the official AMP plugin with WordPress 6.7 or newer, you may encounter this error when validating your AMP pages:

The attribute ‘style amp-custom’ in tag ‘style amp-custom’ is set to the invalid value…

The issue stems from invalid CSS selectors automatically inserted by WordPress into AMP pages. Specifically, selectors like:

Advertisement
Saksham Bharat 2026
Saksham Bharat 2026
A multi-stakeholder dialogue on skilling gap in Cybersecurity, Data Resilience and AI — and the roadmap to a Saksham Bharat.
Register Now →
VeeamON 2026 Tour India - Mumbai
VeeamON 2026 Tour India - Mumbai
A VeeamON 2026 India Leadership Series Mumbai for senior public sector and government technology leaders.
Register Now →
Cyber Surakshit Uttar Pradesh
Cyber Surakshit Uttar Pradesh
Find out strategies, frameworks and solutions for building a resilient and secure digital ecosystem across Uttar Pradesh.
Register Now →
VeeamON 2026 Tour India - Bengaluru
VeeamON 2026 Tour India - Bengaluru
A VeeamON 2026 India Leadership Series Bengaluru for senior public sector and government technology leaders.
Register Now →
VeeamON 2026 Tour India - Delhi
VeeamON 2026 Tour India - Delhi
A VeeamON 2026 India Leadership Series Delhi for senior public sector and government technology leaders.
Register Now →
Infosec Reimagined
Infosec Reimagined
Infosec Reimagined 2026 is the premier information security summit where top leaders—CISOs, CROs, CIOs, CTOs and risk executives—converge to redefine cyber resilience.
Register Now →
Digital Senate
Digital Senate
Digital Senate is a premier conference uniting government leaders, technologists and innovators to share ideas, success stories and strategies on digital governance, public sector transformation, cybersecurity and emerging technologies in India.
Register Now →
CIO Prism
CIO Prism
CIO Prism unites forward-thinking technology leaders to exchange transformative insights, shape digital strategies, and foster innovation, empowering enterprises to excel in an era of rapid technological change.
Register Now →

The issue stems from invalid CSS selectors automatically inserted by WordPress into AMP pages. Specifically, selectors like:

<style amp-custom>
img:is([sizes=”” i], [sizes^=”auto,” i]) {
contain-intrinsic-size: 3000px 1500px;
}
</style>

The i flag inside attribute selectors is not valid AMP-compliant CSS, and causes your AMP pages to fail validation.

Advertisement

Let’s walk through all the ways to fix it, from safe and recommended to advanced and temporary.


✅ Recommended Fixes

1. Create a Custom Plugin to Disable Auto-Sizes in AMP

This is the safest and most future-proof method. You’ll disable the auto-sizes feature only for AMP requests, preventing the faulty CSS from being injected.

🔧 Steps:

  1. Go to your website files via FTP, cPanel, or your local WordPress install.

    Advertisement
  2. Navigate to:

    wp-/plugins/
  3. Create a new file:

    disable-amp-auto-sizes.php
  4. Open it in a code editor and paste:

    <?php
    /*
    Plugin Name: Disable AMP Auto Sizes
    Description: Disables auto sizes attribute on AMP pages to fix invalid CSS in WordPress 6.7+
    Version: 1.0
    */
    function amp_disable_img_auto_sizes() {
    if ( function_exists( ‘amp_is_request’ ) && amp_is_request() ) {
    return false;
    }
    return true;
    }
    add_filter( ‘wp_img_tag_add_auto_sizes’, ‘amp_disable_img_auto_sizes’ );
  5. Save the file.

  6. In your WordPress dashboard, go to Plugins > Installed Plugins and activate “Disable AMP Auto Sizes”.

  7. Go to AMP > Tools > Purge AMP Cache to refresh old AMP pages.

  8. Clear any page caching plugin or server cache (like LiteSpeed, WP Rocket, or Cloudflare).

✅ You’re done. AMP validation should now pass.


2. Use a Child Theme’s functions.php File

If you prefer not to create a plugin, you can add the same filter to your child theme’s functions.php file.

⚠️ Do not modify your main theme’s functions.php — changes will be lost during updates.

🔧 Steps:

  1. Make sure a child theme is active. If not, install one. For Newspaper theme users, download the tagDiv child theme here.

  2. Open:

    wp-content/themes/tagdiv-child/functions.php
  3. Add this code at the bottom:

    function amp_disable_img_auto_sizes() {
    if ( function_exists( 'amp_is_request' ) && amp_is_request() ) {
    return false;
    }
    return true;
    }
    add_filter( 'wp_img_tag_add_auto_sizes', 'amp_disable_img_auto_sizes' );
  4. Save and clear cache.

✅ This achieves the same effect but uses your theme instead of a plugin.


🛠️ Advanced (Not Recommended): Edit WordPress Core File

⚠️ Only for use or experimentation. Not safe for production or future updates.

This method involves commenting out the line of code in WordPress core that inserts the invalid CSS.

🔎 How to Find the Code:

  1. Go to:

    wp-includes/media.php
  2. Search for this line (introduced in WordPress 6.7.1):

    $styles .= 'img:is([sizes="auto" i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}';
  3. Simply comment it out:

    // $styles .= 'img:is([sizes="auto" i],[sizes^="auto," i]){contain-intrinsic-size:3000px 1500px}';
  4. Save the file, clear cache and test again.

✅ The CSS will no longer be injected.

❌ But: WordPress updates will overwrite this file, so this fix won’t last unless you repeat it after every update.


💬 Frequently Asked Questions

Q: Why is this CSS even there?
A: WordPress 6.7+ introduced automatic handling of <img sizes="auto"> to improve responsive images. The CSS is valid for normal browsers, but AMP does not support the i flag in selectors.

Q: Will disabling auto-sizes break images?
A: No, AMP already optimises image loading. Removing auto-sizes will not noticeably affect layout or performance.

Q: I’m using the Newspaper theme. Which functions.php should I use?
A: Only use the one inside your child theme. If you’re unsure, install the tagDiv Child Theme and activate it.


🧪 Test Your Fix

Use either of the following tools to re-test your AMP page:


🎉 Finally

The [sizes="auto" i] issue is a of an update in WordPress that doesn’t fully account for AMP CSS limitations. While WordPress may resolve this in future versions, the above workarounds will help you maintain a clean, validated AMP setup in the meantime.

The best and safest way is to use a small custom plugin that disables auto-sizes only for AMP pages — no risk to your theme or core.

Let me know if you want a downloadable plugin ZIP version or if you’d like to publish this as a post with custom screenshots or code blocks.

Get the day's headlines from Tech Observer straight in your inbox

By subscribing you agree to our Privacy Policy, T&C and consent to receive newsletters and other important communications.
Tech Observer Desk
Tech Observer Desk
Tech Observer Desk at TechObserver.in is a team of technology reporters led by a senior editor who brings latest updates and developments from the world of technology.
- Advertisement -
Powered By Veeam Logo
- Advertisement -

Subscribe to our Newsletter

By subscribing you agree to our Privacy Policy, T&C and consent to receive newsletters and other important communications.
- Advertisement -

India to Lead Global IT Security Standards Body for Two Years

India will chair the Common Criteria Development Board from April 2026, gaining influence over international IT security certification standards recognised by 38 countries.

RELATED ARTICLES