---
title: "Customising your AMP sub-theme"
date: "2019-09-26T11:00:51+00:00"
summary: "Customize your AMP sub-theme with our comprehensive guide. Learn about CSS limitations, useful modules, and best practices for optimizing content. Discover how to create lightweight, mobile-friendly pages that load quickly and effectively."
image:
type: "page"
url: "/drupal-starter-kits/add-ons/site-studio/customising-your-amp-sub-theme"
id: "27757090-6025-4710-9592-3fc851210fd2"
---

Table of contents will be added

Now that you’ve set up AMP and created a sub-theme, you’ll need to create CSS to style your pages. In this guide, we'll cover the following topics:

*   [Limitations](#limitations)
    
*   [Useful modules](#useful-modules)
    
*   [Identifying content for AMP optimisation](#identifying-amp-content)
    
*   [Block and content type optimisation](#block-content-optimisation)
    
*   [Recommended approach to CSS](#css-approach)
    

Limitations
-----------

AMP (Accelerated Mobile Pages) are a stripped down form of HTML, designed to be lightweight and serve mobile content much faster than regular pages. Naturally, this creates limitations to ensure fast delivery of content.

### No Javascript

Custom JS and additional libraries can add a lot of weight to page load times, so AMP pages do not support these.

### CSS size

Your AMP sub-theme CSS styles (which are actually held in a Drupal `html.twig` file) cannot exceed 75kb.

See [recommended approach to CSS](#css-approach) for more info.

### Disallowed CSS

See the [Disallowed styles](https://amp.dev/documentation/guides-and-tutorials/develop/style_and_layout/style_pages/#disallowed-styles) section on the amp.dev website for latest information.

### Custom fonts

Any **imported** fonts you’ve specified in  > `Website settings` > `Font libraries` will be available to your AMP sub-theme to use in CSS.

The following origins are whitelisted by AMP:

*   Typography.com: [https://cloud.typography.com](https://cloud.typography.com)
    
*   Fonts.com: [https://www.fonts.com/](https://www.fonts.com/)
    
*   Google Fonts: [https://fonts.google.com/](https://fonts.google.com/)
    
*   Typekit: [https://use.typekit.net](https://use.typekit.net)
    
*   Font Awesome: [https://fontawesome.com/](https://fontawesome.com/)
    

**Uploaded** font packages will not work unless you create `@font-face` declarations for these fonts in your sub-theme CSS file. These can be copied from the `sites/default/files/cohesion/styles/base/stylesheet.min.css` file.

This also applies to icon fonts specified in  > `Website settings` > `Icon libraries`.

Important

Make sure that any custom font you use is as lightweight as possible, as this will impact page load time.

Useful modules
--------------

Module

Description

[Field Formatter Class](https://www.drupal.org/project/field_formatter_class)

Allows classes to be added to the outer wrapper of any Drupal field display, which provides more control for theming.

[Title Field for Manage Display](https://www.drupal.org/project/title_field_for_manage_display)

Creates a `Title` field in content types that shows up in the `Manage display` tab. Allows more control over page title placement.

[Breadcrumb Extra Field](https://www.drupal.org/project/breadcrumb_extra_field)

Creates a `Breadcrumb` field in content types that shows up in the `Manage display` tab. Allows more control over breadcrumb placement.

[Context](https://www.drupal.org/project/context) (and Context UI submodule)

In combination with `context visibility` settings on Site Studio elements, you can create AMP-alternative content. E.g. replacing `Picture` with `Image`.

Identifying content for AMP optimisation
----------------------------------------

Initially your AMP pages will look very different to regular pages as no styles will be applied - these have to be generated manually.

We recommend you identify a content type that is most likely to benefit from AMP optimisation (eg. blog) as a starting point. You can then expand to other content types as necessary, providing you do not exceed the 50kb CSS limit.

Block and content type optimisation
-----------------------------------

Once you’ve identified a content type to work with, you may need to reorganise your block and content type field placement to provide the best user experience. Site Studio templated content (master templates, content templates etc) are not supported with AMP themes.

Important

Select the correct tab before making changes to block or content type field layout, so that other displays are unaffected. For blocks this is your sub-theme, for content types it will be `AMP`.  
  
Make sure any fields on your content type are using the correct formatter. For example, `Image` needs to be changed to `AMP Image`.

See the [useful modules](#useful-modules) section for some community modules that will help with this process.

Recommended approach to CSS
---------------------------

To keep your theme CSS as light as possible, we recommend using a CSS preprocessor such as SCSS. By setting the SCSS output style to `compressed`, it will minify the CSS into a single line and provide room for extra CSS.

### Best practice

*   Keep CSS selectors as short as possible - single-level element (e.g. `H1`) or class (e.g. `.myclass`) selectors are ideal.
    
*   Never use ID selectors (e.g. `#myid`) as these are much harder to override.
    
*   If multi-level selectors are necessary, limit to no more than three levels (e.g. `ul li a`) - if possible add classes to these elements to give more control.
    
*   Don’t use an autoprefixer - whilst this is normally recommended for legacy browser support, AMP is a modern development framework that targets mobile devices that don’t require autoprefixing. It will also reduce the amount of CSS generated.
    
*   Keep it simple - your AMP pages won’t always look the same as your regular pages, given that page load speed is the priority.
    

### CSS structure

Whilst the CSS you define for your AMP sub-theme will differ from project to project, we recommend using the following outline.

CSS section

Description

`@font-face` declarations

Always put your font declarations first, so that you can specify `font-family` settings for any following selectors.

Site Studio grid styles

As no external styles are loaded, you will need to duplicate Site Studio’s grid CSS to implement a responsive layout. These include `coh-row`, `coh-row-inner`, `coh-column` and `coh-col-*` classes and associated styles.

Site Studio base styles

Some styles that you’ve defined through Site Studio base styles may need duplicating. For example `heading`, `list` and `paragraph` styles.

Drupal core styles

you may need to duplicate some of Drupal's core CSS. Examples include `hidden`, `visually-hidden`, `focusable` and `invisible`.

Drupal element styles

CSS that targets Drupal elements, blocks or fields. This would include styles for any custom classes you’ve added to content type fields.

Site Studio custom styles

Some styles that you’ve defined through Site Studio custom styles may need duplicating.

Site Studio inline element styles

Styles that you’ve applied directly to Site Studio elements through the `Styles` tab.

Useful resources
----------------

*   [AMP compatibility](/drupal-starter-kits/add-ons/site-studio/amp-compatibility "AMP compatibility")
*   [AMP installation and setup guide](/drupal-starter-kits/add-ons/site-studio/amp-installation-and-setup-guide "AMP installation and setup guide")