AMP has the goal of making mobile sites load faster and providing a better experience for users. Google and the AMP Project are making a big push to get AMP adopted across the web, and they’re already doing well. Automattic is adding AMP support to WordPress.com, Pinterest is AMPing itself up, Twitter has pledged support as have Chartbeat, Parse.ly, Adobe Analytics & LinkedIn, and we’re seeing AMP versions come into the mix for the popular sites Wall Street Journal, Buzzfeed, The Guardian, BBC News, The New York Times and several others.
The reason all these companies are getting on board is simple: load speed. There’s no debating that faster sites are better, so in this article I won’t be preaching to the choir by going into all the reasons why that’s the case. The⚡ Highlighting in Search Results. Quick Tip: Make AMP’s Inline CSS Easier With Jade or PHP. Validator.ampproject. Supported CSS. Like all web pages, AMP pages are styled with CSS, but you can’t reference external stylesheets (with the exception of custom fonts) and inline style attributes aren’t allowed.
Also, certain style properties related to animations have been disallowed due to performance implications, and the embedded style tag must be in the <head> of the page. These different kinds of limitations are there to improve the performance of your pages, but can be overwhelming at first. When in doubt, always test your styles using the AMP validator. Even though inline stylesheets add bytes to every page, the saved round trip request to another external file would be even slower. Having your styles in the <head> of the page effectively means that all your CSS becomes critical CSS that is loaded before the rest of the page is loaded, so only include what you need.
Read on to learn how to style your AMP pages: Learn more about critical CSS in this article, Understanding Critical CSS. Add styles to a page. Style & layout. Styling and layout on AMP HTML pages is very similar to normal HTML pages – in both cases, you'll use CSS.
However, AMP limits some use of CSS for performance and usability reasons, while expanding responsive design capabilities with features like placeholders & fallbacks, advanced art direction via srcset and the layout attribute for better control over how your elements display. Add styles to a page Add all CSS inside a <style amp-custom> tag in the head of the document.
For example: Define component styles with class or element selectors using common CSS properties. <body><p>Hello, Kitty. Layout elements responsively Specify the size and position for all visible AMP elements by providing a width and height attribute. Set the layout to responsive. Provide placeholders & fallbacks The built-in support for placeholders and fallbacks means your users never have to stare at a blank screen again. Art direct your images Validate your styles and layout. Quick Tip: Make AMP’s Inline CSS Easier With Jade or PHP. Google Developers. Google Developers. Accelerated Mobile Pages Project. Up and Running With AMP - CSS and AMP. Accelerated Mobile Pages Project – AMP.