How to Write Schema for SEO

Updated on April 13th, 2024 at 09:45 pm

Writing schema markup for SEO isn’t very complicated.

If you use JSON-LD and stick to established types of content, writing schema is very simple.

Very often, sites bundle automated schema options out of the box or allow you to programmatically roll schema types out across your website.

However, schema markup evolves, Google regularly update the types of schema they can offer increased exposure to in search or ways which schema can support pages, content and products on your website.

Here are tips on how to write perfect schema markup every time, so you can keep errors to a minimum and guarantee your schema validates.

How to Write JSON Schema

Writing JSON-LD (JavaScript Object Notation for Linked Data) schema is the easiest option for creating you own customised schema markup for your website pages.

It is a very simple code base which is easy to understand, edit and reuse once you get to grips with it.

Opening Your JSON-LD

Correctly opening a JSON-LD script will allow your code to work as expected. Without the appropriate MIME type indicating that it is JSON-LD you may see issues on your live pages and search engines may not be able to correctly interpret the code.

<script type="application/ld+json">

Open your code editor or document and enter the above to open a JSON-LD script.

Curly Braces

Curly braces in JSON-LD schema are used to encapsulate objects within your JSON-LD.

For example, you can include objects like; “name”, “@type”, “description”, “brand” etc.

Let’s say you were creating JSON-LD to markup a financial product page, elements you might include in your first array should include:

<script type="application/ld+json">
    {
      "@context": "https://schema.org/",
      "@type": "FinancialProduct",
      "annualPercentageRate": "2.9",
      "interestRate": "2.74",
      "name": "Search/Natural Example Finance Product",
      "description": "Save or invest in a SearchNatural financial product. You can pay in many pounds. Savings account cost from £2"
}

Your first set of curly braces might include;

  • @context – is a fundamental element of creating JSON-LD, including it maps the the terms used within your JSON-LD document and the globally accepted schema markup standards
  • @type – indicates that this particular document represents the entity of a “FinancialProduct”

Both of these concepts are critical to JSON-LD document creation.

Without “@context” search engines will have no way to relate your mark up to entities and without “@type” search engines will be less clear on the types of webpage objects you’re marking up.

  • “annualPercentageRate”
  • “interestRate”
  • “description”
  • “brand”

Are all examples of optional object types.

Both “annualPercentageRate” and “interestRate” are specific to the type of “FinancialProduct”.

Both “description” and “brand” can be used across a variety of schema types.

You can include any number of curly braces within your JSON-LD schema based on the page you’re marking up and the detail level you want to go to.

Nesting

You can use multiple instances of curly braces to “nest” objects and create complex relational data structures in your JSON-LD which infer relevance from the hierarchical structure of the schema markup.

"brand": {
        "@type": "Brand",
        "name": "Search/Natural"
      },
      "aggregateRating": {
          "@type": "AggregateRating",
          "ratingValue": "4.4",
          "reviewCount": "89"
        },
      "offers": {
        "@type": "Offer",
        "url": "https://www.searchnatural.co.uk/product-offer/",
        "itemCondition": "https://schema.org/NewCondition",
        "availability": "https://schema.org/InStock",
        "price": "39.99",
        "priceCurrency": "USD",
        "priceValidUntil": "2020-11-20",
        "shippingDetails": {
          "@type": "OfferShippingDetails",
          "shippingRate": {
            "@type": "MonetaryAmount",
            "value": "3.49",
            "currency": "USD"
          },
          "shippingDestination": {
            "@type": "DefinedRegion",
            "addressCountry": "US"
          },
          "deliveryTime": {
            "@type": "ShippingDeliveryTime",
            "handlingTime": {
              "@type": "QuantitativeValue",
              "minValue": "0",
              "maxValue": "1"
            },
            "transitTime": {
              "@type": "QuantitativeValue",
              "minValue": "1",
              "maxValue": "5"
            }

In the above example we’ve included;

  • “offers” – indicating this markup relates to a product
    • Offers include objects like; “url”, “itemCondition”, “price” etc.
  • Nested within “offers” we also include the object “shippingDetails”
    • Nested within “shippingDetails” we include the objects;
      • “shippingRate”
      • “shippingDestination”
      • “deliveryTime”
      • “transitTime”

With this type of nesting, search engines can easily infer, from the schema markup you’ve provided embedded within your page, what destinations the product can ship to, how long it will take to arrive and your shipping fees.

Square Brackets or Arrays

Similar to regular JSON arrays, square brackets in JSON-LD can be used to express lists of values associated with an on page element, object or item.

     "image": [
        "https://searchnatural.co.uk/image/financial-product.png",
        "https://searchnatural.co.uk/image/financial-product-specs.png",
        "https://searchnaturalapp.com/image/financial-product-terms.png",
        "https://searchnatural.co.uk/image/financial-product-bonus.png",
        "https://searchnatural.co.uk/image/financial-product-graph.png"
      ],

In our example, we’ve used a pair of square brackets to define a list of images which relate to the particular financial product we are creating schema markup for.

Where you have multiple different on page elements, you can use an array to markup each element easily.

How to write FAQ Schema

FAQ schema mark up is one of the simplest schema types you can produce.

It is easy to replicate and very simple to edit and update to reflect the set of questions and can help your content gain additional visibility in search results (although Google has an unharmonious relationship with FAQ schema).

 <script type="application/ld+json">
    {
      "@context": "https://schema.org",
      "@type": "FAQPage",
      "mainEntity": [{
        "@type": "Question",
        "name": "How do you write JSON-LD FAQ Schema?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "Write JSON-LD FAQ schema by including a <script> tag on your website which is type='application/ld+json' this will indicate to search engines that your <script> contains JSON-LD. Then add appropriate mainEntity, acceptedAnswer, answer type and text fields"
        }
      }, {
        "@type": "Question",
        "name": "Why should you choose JSON-LD schema?",
        "acceptedAnswer": {
          "@type": "Answer",
          "text": "JSON-LD is the best way to markup webpages with schema because it is easy to write and edit, lightweight and simple to embed into pages across almost every CMS. If you're marking up multiple pages, you can do so programmatically with tools like Google Tag Manager. "
        }
      }]
    }
    </script>

What is the best Schema to Mark up SEO Content?

The best type of schema to mark up your content with is undoubtedly JSON-LD schema.

JSON-LD is the best type of schema markup because:

it is easy to create, easy to edit and quick and simple to update when something on your webpage changes (if you’ve manually inserted it into your pages).

While RDFa and Microdata are just as powerful as JSON-LD, they are a little more complex to write than the equivalent JSON-LD structured data markup.

Arguably, they’re also not as simple to add to pages which you already have live.

However, both Microdata and RDFa are effective but both are best added to website pages as code is being written.

Most won’t consider schema during the development phase of your website, so if you’re retroactively adding structured data, writing it as JSON-LD is your best bet.

What is the Best Type of Schema for SEO?

The type of schema you need to mark up your pages depends a lot on what the contents of the page covers.

Traditionally, you’ll want to align;

  • long copy content pages or “blog” pages with article schema.
  • product pages tend to use product structured data
  • website page is popular for other website pages
  • organization schema and or LocalBusiness schema is best used on your homepage or on your contact us page, it isn’t needed on every page.

If you’re looking for help trying to understand the type of schema you need for your site, then try our schema markup picker tool.

How to Write RDFa Schema

The equivalent financial product schema, rewritten into RDFa schema is included below.

<div vocab="https://schema.org/" typeof="Product">
  <link property="alternateType" href="https://schema.org/FinancialProduct" />
  <span property="sku">prod-12345</span>
  <span property="gtin14">12345678901234</span>
  <link rel="image" href="https://searchnatural.co.uk/photos/16x9/product.jpg" />
  <link rel="image" href="https://searchnatural.co.uk/photos/4x3/product.jpg" />
  <link rel="image" href="https://searchnatural.co.uk/photos/1x1/product.jpg" />
  <span property="name">Nice product</span>
  <span property="description">product with clean lines</span>
  <div property="brand" typeof="Brand">
    <span property="name">Search/Natural</span>
  </div>
  <div property="aggregateRating" typeof="AggregateRating">
    <span property="ratingValue">4.4</span>
    <span property="reviewCount">89</span>
  </div>
  <div property="offers" typeof="Offer">
    <a property="url" href="https://www.searchnatural.co.uk/product-offer/">Link to Offer</a>
    <link property="itemCondition" href="https://schema.org/NewCondition" />
    <link property="availability" href="https://schema.org/InStock" />
    <span property="price" content="39.99">$39.99</span>
    <span property="priceCurrency" content="USD">USD</span>
    <time property="priceValidUntil" datetime="2020-11-20">November 20, 2020</time>
    <div property="shippingDetails" typeof="OfferShippingDetails">
      <div property="shippingRate" typeof="MonetaryAmount">
        <span property="value" content="3.49">$3.49</span>
        <span property="currency" content="USD">USD</span>
      </div>
      <div property="shippingDestination" typeof="DefinedRegion">
        <span property="addressCountry">US</span>
      </div>
      <div property="deliveryTime" typeof="ShippingDeliveryTime">
        <div property="handlingTime" typeof="QuantitativeValue">
          <span property="minValue" content="0">0</span> -
          <span property="maxValue" content="1">1</span> day handling time
        </div>
        <div property="transitTime" typeof="QuantitativeValue">
          <span property="minValue" content="1">1</span> -
          <span property="maxValue" content="5">5</span> days transit time
        </div>
      </div>
    </div>
  </div>
  <div property="review" typeof="Review">
    <span property="reviewBody">I love this product. It is perfect for optimizing my website.</span>
    <div property="reviewRating" typeof="Rating">
      <span property="ratingValue">4</span>
      <span property="bestRating">5</span>
    </div>
    <time property="datePublished" datetime="2023-01-12">January 12, 2023</time>
    <div property="author" typeof="Person">
      <span property="name">Fred Benson</span>
    </div>
  </div>
  <div property="review" typeof="Review">
    <span property="reviewBody">The product does exactly as promised</span>
    <div property="reviewRating" typeof="Rating">
      <span property="ratingValue">5</span>
      <span property="bestRating">5</span>
    </div>
    <time property="datePublished" datetime="2023-01-12">January 12, 2023</time>
    <div property="author" typeof="Person">
      <span property="name">Judith Chalmers</span>
    </div>
  </div>
  <div property="review" typeof="Review">
    <span property="reviewBody">This is the best product you could get</span>
    <div property="reviewRating" typeof="Rating">
      <span property="ratingValue">4</span>
      <span property="bestRating">5</span>
    </div>
    <time property="datePublished" datetime="2023-01-12">January 12, 2023</time>
    <div property="author" typeof="Person">
      <span property="name">Harry Bould</span>
    </div>
  </div>
</div>

The important points to remember if you’re writing schema markup in RDFa format for your website is.

  • vocab attribute: Is used in the opening <div> to help establish that this is Schema and this is equivalent to the “typeof” product.
  • The vocabulary (defined as, “https://schema.org/&#8221;) Helps search engines understand the element and its descendants are part of the markup.
  • typeof attribute: This attribute is used to specify the type of the current item. It indicates that the element and its descendants represent an instance of the specified type.
  • The property attribute: defines all of the related “property” attributes of the item. It specifies the name of the property from the vocabulary defined in the vocab attribute. For example, prod-12345 specifies that “prod-12345” is the value of the “sku” property of the product. Property is also used to tie content elements to recognised schema categories on your website define reviews, review ratings and publication dates for your schema.
  • content attribute: This attribute specifies the value of the property. It is often used in conjunction with the property attribute. For example, $39.99 specifies that the price property has the value “39.99” in the content attribute, and “$39.99” is displayed as the text content.
  • href attribute: This attribute specifies the value of a property as a URL. It is similar to the content attribute but used to link related resources or provide URLs for properties like images or offers. For example, links the product image.
  • datetime attribute: This attribute specifies the value of a property as a date or time. It is used for properties like datePublished. For example, January 12, 2023 specifies the date when a review was published.

Essentially, you can add the code as a block where relevant to do on your website similar to how you’d add HTML blocks.

How to Write Microdata Schema

Microdata is another option for schema and providing structured data to search engines.

<div itemscope itemtype="https://schema.org/Product" itemid="#product">
  <link itemprop="alternateType" href="https://schema.org/FinancialProduct" />
  <span itemprop="sku">prod-12345</span>
  <span itemprop="gtin14">12345678901234</span>
  <link itemprop="image" href="https://searchnatural.co.uk/photos/16x9/product.jpg" />
  <link itemprop="image" href="https://searchnatural.co.uk/photos/4x3/product.jpg" />
  <link itemprop="image" href="https://searchnatural.co.uk/photos/1x1/product.jpg" />
  <span itemprop="name">Nice product</span>
  <span itemprop="description">product with clean lines</span>
  <div itemprop="brand" itemscope itemtype="https://schema.org/Brand">
    <span itemprop="name">Search/Natural</span>
  </div>
  <div itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">
    <span itemprop="ratingValue">4.4</span>
    <span itemprop="reviewCount">89</span>
  </div>
  <div itemprop="offers" itemscope itemtype="https://schema.org/Offer">
    <a itemprop="url" href="https://www.searchnatural.co.uk/product-offer/">Link to Offer</a>
    <link itemprop="itemCondition" href="https://schema.org/NewCondition" />
    <link itemprop="availability" href="https://schema.org/InStock" />
    <span itemprop="price" content="39.99">$39.99</span>
    <span itemprop="priceCurrency" content="USD">USD</span>
    <time itemprop="priceValidUntil" datetime="2020-11-20">November 20, 2020</time>
    <div itemprop="shippingDetails" itemscope itemtype="https://schema.org/OfferShippingDetails">
      <div itemprop="shippingRate" itemscope itemtype="https://schema.org/MonetaryAmount">
        <span itemprop="value" content="3.49">$3.49</span>
        <span itemprop="currency" content="USD">USD</span>
      </div>
      <div itemprop="shippingDestination" itemscope itemtype="https://schema.org/DefinedRegion">
        <span itemprop="addressCountry">US</span>
      </div>
      <div itemprop="deliveryTime" itemscope itemtype="https://schema.org/ShippingDeliveryTime">
        <div itemprop="handlingTime" itemscope itemtype="https://schema.org/QuantitativeValue">
          <span itemprop="minValue" content="0">0</span> -
          <span itemprop="maxValue" content="1">1</span> day handling time
        </div>
        <div itemprop="transitTime" itemscope itemtype="https://schema.org/QuantitativeValue">
          <span itemprop="minValue" content="1">1</span> -
          <span itemprop="maxValue" content="5">5</span> days transit time
        </div>
      </div>
    </div>
  </div>
  <div itemprop="review" itemscope itemtype="https://schema.org/Review">
    <span itemprop="reviewBody">I love this product. It is perfect for optimizing my website.</span>
    <div itemprop="reviewRating" itemscope itemtype="https://schema.org/Rating">
      <span itemprop="ratingValue">4</span>
      <span itemprop="bestRating">5</span>
    </div>
    <time itemprop="datePublished" datetime="2023-01-12">January 12, 2023</time>
    <div itemprop="author" itemscope itemtype="https://schema.org/Person">
      <span itemprop="name">Fred Benson</span>
    </div>
  </div>
  <div itemprop="review" itemscope itemtype="https://schema.org/Review">
    <span itemprop="reviewBody">The product does exactly as promised</span>
    <div itemprop="reviewRating" itemscope itemtype="https://schema.org/Rating">
      <span itemprop="ratingValue">5</span>
      <span itemprop="bestRating">5</span>
    </div>
    <time itemprop="datePublished" datetime="2023-01-12">January 12, 2023</time>
    <div itemprop="author" itemscope itemtype="https://schema.org/Person">
      <span itemprop="name">Judith Chalmers</span>
    </div>
  </div>
  <div itemprop="review" itemscope itemtype="https://schema.org/Review">
    <span itemprop="reviewBody">This is the best product you could get</span>
    <div itemprop="reviewRating" itemscope itemtype="https://schema.org/Rating">
      <span itemprop="ratingValue">4</span>
      <span itemprop="bestRating">5</span>
    </div>
    <time itemprop="datePublished" datetime="2023-01-12">January 12, 2023</time>
    <div itemprop="author" itemscope itemtype="https://schema.org/Person">
      <span itemprop="name">Harry Bould</span>
    </div>
  </div>
</div>

  • The opening <div> element is HTML used to define the opening element of your Schema mark up.
  • itemscope indicates that this is the start of a set of structured data for your website.
  • itemtype set to itemtype=”https://schema.org/Product&#8221; specifies the type of item being described, in the case of our example it ties our set of code to the defined schema vocabulary found on schema.org/Products
  • <link> is used to link to signify a link to a property of the current item. In this case, it is the alternate type of the product. href=”https://schema.org/FinancialProduct&#8221; e.g. pointing to the schema vocabulary FinacialProduct
  • <span> are HTML elements used to enclose text, so within the span elements is where you’ll find information related to the products which can appear on the page, whereas itemprop is used for data won’t be visible to the user.

So think of <span> as elements which could appear as visible to users on the page whereas <div> are less likely to be visible elements and use the “itemprop” attribute to help define the related schema vocabulary, like; offers, link, review.

Essentially, Microdata relies on HTML attributes to annotate your HTML elements with structured data mark up.

Publish your Schema

Once you’ve written your schema, all that is left to do is publish your schema within your webpages.

You can either do this manually, by adding it to individual pages as embedded HTML elements or programatically, by using something like Google Tag Manger to rollout your schema.

Also, before you publish your schema markup, make sure you know how to validate and check your schema markup to make sure it works.

Use the schema markup validator and Google’s rich result test tool.

Use a Plugin

If writing schema mark up seems to complex or too bitty, don’t worry!

Most CMS (content management systems) have the ability either create and publish schema usually without you having to do anything at all other than select your schema.

However, it is worth bearing in mind that CMS produced schema can be very generic and often won’t reflect the nuance of your products, webpages and the services and products you offer.

We’ll write Schema for You

We can help you write specific, detailed and bespoke schema which will work and validate correctly on your product pages.

Try our schema mark up writing service, just choose your schema and place your order and we’ll do the rest.

Try our other SEO products and courses to learn;

Google tag manager SEO: How to optimise a website with Google tag manager

Published on: 23/02/2024

About Ben

Ben is the founder and SEO director of Search Natural. He spent 8 years working in SEO at some of the biggest comparison sites in the UK before setting up his own business to work as an SEO specialist with clients around the world.