Recipe Schema Framework

Use conditional-logic schema generation to keep Recipe markup aligned with real page state and avoid stale or invalid static templates.

When To Use It

Google Search CentralRecipe documentation

Use for recipe pages with complete ingredients, instructions, and preparation details.

Key Implementation Documentation Highlights

  • Required properties: name (the name of the dish) and image (the completed dish). Google lists no other required properties.
  • Recommended properties: aggregateRating, author, cookTime, prepTime, totalTime, datePublished, description, keywords, nutrition.calories, recipeCategory, recipeCuisine, recipeIngredient, recipeInstructions, recipeYield, video.
  • Times are ISO 8601 durations (for example PT1H30M). Always use cookTime and prepTime together, and provide totalTime or both of them.
  • If nutrition.calories is present, recipeYield is required and must state the number of servings as a number (for example "4"); extra yields such as "24 cookies" can follow.
  • recipeInstructions: prefer HowToStep (each step needs text or itemListElement) or HowToSection (name plus itemListElement of HowToSteps). Include only instruction text: no "Directions", "Step 1" or "Watch the video", and no step numbers in step names.
  • Images must be crawlable, indexable and show the dish; for best results provide several high-resolution images (at least 50K pixels, width x height) in 16x9, 4x3 and 1x1. keywords are comma separated and must not repeat recipeCategory or recipeCuisine.
  • Host carousels need ItemList markup on a summary page: each ListItem needs a position and a unique canonical url.
  • Google expects content parity: every marked-up value must match what users can see on the page.
  • Use the Rich Results Test and URL Inspection to validate rendering, eligibility, and crawlability.

Template Approach

const pageData = {
  title: "Lemon Garlic Sheet Pan Salmon",
  image: "https://www.example.com/img/salmon-16x9.jpg",
  description: "Salmon fillets roasted with lemon, garlic and green beans on one pan.",
  authorName: "Maya Ortiz",
  publishDate: "2026-03-18"
};

const staticTemplate = {
  "@context": "https://schema.org",
  "@type": "Recipe",
  "name": pageData.title,
  "image": [pageData.image],
  "description": pageData.description,
  "author": { "@type": "Person", "name": pageData.authorName },
  "datePublished": pageData.publishDate,
  "prepTime": "PT10M",
  "cookTime": "PT15M",
  "recipeYield": "4",
  "recipeIngredient": ["4 salmon fillets", "1 lb green beans", "1 lemon, sliced"],
  "recipeInstructions": [
    { "@type": "HowToStep", "text": "Toss the green beans with oil on a sheet pan." },
    { "@type": "HowToStep", "text": "Add the salmon, top with lemon and roast for 15 minutes." }
  ]
};

Conditional-logic Framework

const ISO_DATE_TIME = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2}))?(Z|[+-]\d{2}:\d{2})?)?$/;

function isAbsoluteUrl(value) {
  return typeof value === "string" && /^https?:\/\/[^\s/?#]+\.[^\s/?#]+(?:[/?#]\S*)?$/i.test(value);
}

// Returns the ISO 8601 string unchanged (timezone offset kept), or null if unparseable.
function toIsoDateTime(value) {
  if (typeof value !== "string") return null;
  const text = value.trim();
  const m = text.match(ISO_DATE_TIME);
  if (!m) return null;
  const [, y, mo, d, h = "00", mi = "00", s = "00"] = m;
  const date = new Date(Date.UTC(+y, +mo - 1, +d));
  if (date.getUTCMonth() !== +mo - 1 || date.getUTCDate() !== +d) return null;
  if (+h > 23 || +mi > 59 || +s > 59) return null;
  return text;
}

function toIsoDate(value) {
  const iso = toIsoDateTime(value);
  return iso ? iso.slice(0, 10) : null;
}

// Drops null, undefined, "", [] and {} recursively.
function compact(value) {
  if (Array.isArray(value)) {
    const items = value.map(compact).filter((v) => v !== undefined);
    return items.length ? items : undefined;
  }
  if (value && typeof value === "object") {
    const out = {};
    for (const [key, v] of Object.entries(value)) {
      const c = compact(v);
      if (c !== undefined) out[key] = c;
    }
    return Object.keys(out).length ? out : undefined;
  }
  return value === null || value === undefined || value === "" ? undefined : value;
}

function passesPageGates(source) {
  if (source.indexable === false) return false;
  if (source.canonicalUrl && source.url && source.canonicalUrl !== source.url) return false;
  return source.contentVisible !== false;
}

function toNumber(value) {
  if (value === null || value === undefined || value === "" || typeof value === "boolean") return null;
  const num = Number(value);
  return Number.isFinite(num) ? num : null;
}

const isCurrencyCode = (value) => typeof value === "string" && /^[A-Z]{3}$/.test(value);

// Rating or AggregateRating; null when ratingValue falls outside worstRating..bestRating.
function buildRating(input, type) {
  if (!input) return null;
  const best = toNumber(input.bestRating) ?? 5;
  const worst = toNumber(input.worstRating) ?? 1;
  const value = toNumber(input.ratingValue);
  if (value === null || worst >= best || value < worst || value > best) return null;
  const rating = { "@type": type, ratingValue: value, bestRating: best, worstRating: worst };
  if (type === "AggregateRating") {
    const ratingCount = toNumber(input.ratingCount);
    const reviewCount = toNumber(input.reviewCount);
    if (!(ratingCount > 0) && !(reviewCount > 0)) return null;
    rating.ratingCount = ratingCount > 0 ? ratingCount : null;
    rating.reviewCount = reviewCount > 0 ? reviewCount : null;
  }
  return rating;
}

// Review with a valid author name (under 100 characters) and an in-range rating.
function buildReview(input) {
  const authorName = String(input?.authorName ?? "").trim();
  const reviewRating = buildRating(input?.rating, "Rating");
  if (!authorName || authorName.length >= 100 || !reviewRating) return null;
  return {
    "@type": "Review",
    author: { "@type": input.authorType === "Organization" ? "Organization" : "Person", name: authorName },
    reviewRating,
    datePublished: toIsoDate(input.datePublished)
  };
}

const ISO_DURATION = /^P(?=\d|T\d)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+S)?)?$/;

// Minutes (number) become PT#H#M; strings must already be ISO 8601 durations.
function toIsoDuration(value) {
  if (typeof value === "number" && Number.isInteger(value) && value > 0) {
    const hours = Math.floor(value / 60);
    const minutes = value % 60;
    return `PT${hours ? `${hours}H` : ""}${minutes ? `${minutes}M` : ""}`;
  }
  return typeof value === "string" && ISO_DURATION.test(value.trim()) ? value.trim() : null;
}

const STEP_LABEL = /^(directions|instructions|watch the video|step\s*\d+)\s*[:.\-]?\s*/i;
const absoluteUrls = (list) => (list ?? []).filter(isAbsoluteUrl);

// A step video is a Clip of the recipe video: name, startOffset (seconds) and a url that jumps to it.
function buildClip(clip, name) {
  const start = toNumber(clip?.startOffset);
  const end = toNumber(clip?.endOffset);
  if (!name || !Number.isInteger(start) || start < 0 || !isAbsoluteUrl(clip.url)) return null;
  return { "@type": "Clip", name, startOffset: start, endOffset: end > start ? end : null, url: clip.url };
}

function buildStep(step) {
  const text = String(step?.text ?? "").replace(STEP_LABEL, "").trim();
  if (!text) return null;
  const rawName = String(step.name ?? "").trim();
  const name = rawName && !/^step\s*\d+$/i.test(rawName) ? rawName : null;
  return {
    "@type": "HowToStep",
    name,
    text,
    url: isAbsoluteUrl(step.url) ? step.url : null,
    image: isAbsoluteUrl(step.image) && /\.(jpe?g|png|gif)(\?.*)?$/i.test(step.image) ? step.image : null,
    video: buildClip(step.clip, name)
  };
}

// HowToSection needs a name and at least one valid HowToStep.
function buildInstruction(item) {
  if (!Array.isArray(item?.steps)) return buildStep(item);
  const steps = item.steps.map(buildStep).filter(Boolean);
  const name = String(item.sectionName ?? "").trim();
  return name && steps.length ? { "@type": "HowToSection", name, itemListElement: steps } : null;
}

function buildVideo(video) {
  const uploadDate = toIsoDateTime(video?.uploadDate);
  if (!video?.name || !isAbsoluteUrl(video.thumbnailUrl) || !uploadDate || !uploadDate.includes("T")) return null;
  return {
    "@type": "VideoObject",
    name: video.name,
    description: video.description,
    thumbnailUrl: video.thumbnailUrl,
    uploadDate,
    duration: toIsoDuration(video.duration),
    contentUrl: isAbsoluteUrl(video.contentUrl) ? video.contentUrl : null,
    embedUrl: isAbsoluteUrl(video.embedUrl) ? video.embedUrl : null
  };
}

function buildRecipeSchema(source) {
  if (!passesPageGates(source)) return null;

  // Required: name of the dish and at least one crawlable image of it.
  const name = String(source.name ?? "").trim();
  const images = absoluteUrls(source.images);
  if (!name || images.length === 0) return null;

  // prepTime and cookTime only as a pair; totalTime stands alone.
  const prepTime = toIsoDuration(source.prepTime);
  const cookTime = toIsoDuration(source.cookTime);
  const pairOk = Boolean(prepTime && cookTime);

  // Per-serving calories require recipeYield with the number of servings.
  const servings = toNumber(source.servings);
  const recipeYield = Number.isInteger(servings) && servings > 0
    ? [String(servings), ...(source.extraYields ?? [])]
    : null;

  const taxonomy = [source.category, source.cuisine].filter(Boolean).map((v) => v.toLowerCase());
  const keywords = (source.keywords ?? []).filter((k) => !taxonomy.includes(k.toLowerCase()));

  return compact({
    "@context": "https://schema.org",
    "@type": "Recipe",
    name,
    image: images,
    description: source.description,
    author: (source.authors ?? []).map((a) => ({ "@type": a.type === "Organization" ? "Organization" : "Person", name: a.name, url: isAbsoluteUrl(a.url) ? a.url : null })),
    datePublished: toIsoDate(source.datePublished),
    prepTime: pairOk ? prepTime : null,
    cookTime: pairOk ? cookTime : null,
    totalTime: toIsoDuration(source.totalTime),
    recipeYield,
    recipeCategory: source.category,
    recipeCuisine: source.cuisine,
    keywords: keywords.join(", "),
    nutrition: recipeYield && source.caloriesPerServing
      ? { "@type": "NutritionInformation", calories: `${source.caloriesPerServing} calories` }
      : null,
    recipeIngredient: (source.ingredients ?? []).map((i) => String(i).trim()),
    recipeInstructions: (source.instructions ?? []).map(buildInstruction).filter(Boolean),
    aggregateRating: buildRating(source.rating, "AggregateRating"),
    video: buildVideo(source.video)
  });
}

// Usage:
// const source = {
//   url: "https://www.example.com/recipes/lemon-garlic-salmon",
//   canonicalUrl: "https://www.example.com/recipes/lemon-garlic-salmon",
//   indexable: true,
//   contentVisible: true,
//   name: "Lemon Garlic Sheet Pan Salmon",
//   images: [
//     "https://www.example.com/img/salmon-16x9.jpg",
//     "https://www.example.com/img/salmon-4x3.jpg",
//     "https://www.example.com/img/salmon-1x1.jpg"
//   ],
//   description: "Salmon fillets roasted with lemon, garlic and green beans on one pan.",
//   authors: [{ name: "Maya Ortiz", url: "https://www.example.com/authors/maya-ortiz" }],
//   datePublished: "2026-03-18",
//   prepTime: 10,
//   cookTime: 15,
//   totalTime: 25,
//   servings: 4,
//   category: "Dinner",
//   cuisine: "American",
//   keywords: ["weeknight", "sheet pan", "dinner"],
//   caloriesPerServing: 410,
//   ingredients: ["4 salmon fillets", "1 lb green beans", "3 cloves garlic, minced", "1 lemon, sliced", "2 tbsp olive oil"],
//   instructions: [
//     {
//       name: "Prep the pan",
//       text: "Step 1: Heat the oven to 425F and toss the green beans with oil on a sheet pan.",
//       url: "https://www.example.com/recipes/lemon-garlic-salmon#step-1",
//       image: "https://www.example.com/img/salmon-step-1.jpg",
//       clip: { startOffset: 0, endOffset: 45, url: "https://www.example.com/video/salmon?t=0" }
//     },
//     {
//       name: "Add the salmon",
//       text: "Nestle the salmon among the beans, top with garlic and lemon slices.",
//       url: "https://www.example.com/recipes/lemon-garlic-salmon#step-2",
//       image: "https://www.example.com/img/salmon-step-2.jpg",
//       clip: { startOffset: 45, endOffset: 100, url: "https://www.example.com/video/salmon?t=45" }
//     },
//     {
//       name: "Roast",
//       text: "Roast for 12 to 15 minutes, until the salmon flakes easily.",
//       url: "https://www.example.com/recipes/lemon-garlic-salmon#step-3",
//       image: "https://www.example.com/img/salmon-step-3.jpg",
//       clip: { startOffset: 100, endOffset: 160, url: "https://www.example.com/video/salmon?t=100" }
//     }
//   ],
//   rating: { ratingValue: 4.8, ratingCount: 312 },
//   video: {
//     name: "How to make lemon garlic sheet pan salmon",
//     description: "Watch the salmon and green beans go from pan to plate in 25 minutes.",
//     thumbnailUrl: "https://www.example.com/img/salmon-video-thumb.jpg",
//     uploadDate: "2026-03-18T09:00:00-04:00",
//     duration: "PT2M40S",
//     contentUrl: "https://www.example.com/video/salmon.mp4",
//     embedUrl: "https://www.example.com/embed/salmon"
//   }
// };
// const jsonLd = buildRecipeSchema(source);

The Output As An Entity Graph

The conditional-logic output above, parsed in your browser and drawn as the graph a crawler builds from it. Every nested object is a node and the property that holds it is the edge. Tap a node to inspect its properties, or drag to rearrange.

Why Conditional Logic Is Better Than Static Templates

  • Prevents emitting empty, null, or stale fields that frequently trigger rich result warnings.
  • Supports multiple page states (for example: no rating yet, no image yet, no offers yet) without duplicate templates.
  • Lets engineering teams centralize schema policy checks and validation in reusable code paths.
  • Makes large-scale schema maintenance safer when content models evolve over time.

Property Reference

What Google's Recipe documentation requires and recommends, property by property. These are the same rules the SchemaCDN validator checks. Each name links to its schema.org definition.

Required, one of: In recipeInstructions: howToStep requires text or itemListElement.

Recipe properties in Google's documentation
PropertyGoogleExpectsNotes
imageRequiredURL or ImageObject, can repeatProvide an image of the completed dish. Aspect ratios: 16x9, 4x3, 1x1.
nameRequiredTextThe name of the dish.
aggregateRatingRecommendedAggregateRatingThe average review score for the recipe.
authorRecommendedPerson or Organization, can repeatThe person or organization that wrote the recipe.
cookTimeRecommendedDurationISO 8601 duration. , always together with prepTime.
datePublishedRecommendedDateIn ISO 8601 format.
descriptionRecommendedTextA short summary describing the dish.
keywordsRecommendedTextComma separated. , not duplicating recipeCategory or recipeCuisine.
nutritionRecommendedNutritionInformationGoogle documents nutrition.calories. If nutrition.calories is defined, recipeYield must be defined with the number of servings.
nutrition.caloriesRecommendedEnergy or TextCalories per serving.
prepTimeRecommendedDurationISO 8601 duration. , always together with cookTime.
recipeCategoryRecommendedTextThe type of meal or course.
recipeCuisineRecommendedTextThe region associated with the recipe.
recipeIngredientRecommendedText, can repeatOne entry per ingredient.
recipeInstructionsRecommendedHowToStep, HowToSection or Text, can repeatPreferably as HowToStep items.
recipeInstructions.itemListElementOne ofHowToDirection or HowToTip, can repeatHowToStep needs text or itemListElement.
recipeInstructions.textOne ofTextHowToStep needs text or itemListElement.
recipeInstructions.imageRecommendedURL or ImageObjectImage for this step.
recipeInstructions.nameRecommendedTextShort descriptive step name (no step numbers)
recipeInstructions.urlRecommendedURLLinking directly to the step.
recipeInstructions.videoRecommendedVideoObject or ClipVideo or Clip for this step.
recipeYieldRecommendedText or Integer, can repeatThe number of servings as a number.
totalTimeRecommendedDurationOr both cookTime and prepTime (ISO 8601 durations)
videoRecommendedVideoObjectA VideoObject depicting the steps to make the dish.

Explore Other Schema Framework Pages

Return Policy Use to publish a merchant return policy once at the organization level, with offer-level overrides. MerchantReturnPolicy Open Review Snippet Use when a page publishes genuine reviews tied to a clearly identified product, service, or entity. Review Open Shipping Policy Use to publish shipping rates, delivery times and destinations once at the organization level. ShippingService Open Site Name Use on the home page so Google shows the preferred site name in search results. WebSite Open Retired Sitelinks Search Box Use on sites with a functioning internal search endpoint that can accept URL query parameters. WebSite Open Software App (Beta) Use for software product pages that describe platform support and application category clearly. SoftwareApplication Open Limited Speakable Use for news-style pages where specific text segments are appropriate for text-to-speech playback. SpeakableSpecification Open Subscription and Paywalled Content Use for pages with restricted sections so Google can distinguish free previews from protected content. CreativeWork Open Limited Vacation Rental Use for rental property detail pages where booking-relevant amenities and location signals are explicit. VacationRental Open Retired Vehicle Listing Use for inventory pages selling vehicles with standardized listing fields and offer information. Car Open Video Use for pages where a primary video is embedded and key media metadata is visible on-page. VideoObject Open Article Use for editorial pages where the visible content is a complete article with a clear byline and publication timestamps. Article Open Limited Book Actions Use when your page helps users read, preview, or purchase books through clearly described actions. Book Open Breadcrumb Use on pages that belong to a clear hierarchy and display navigational trail links users can follow. BreadcrumbList Open Carousel Use when a page lists multiple related entities in a scannable sequence that can be surfaced as cards. ItemList Open Course Use for educational offerings where curriculum details, provider identity, and delivery context are explicit. Course Open Dataset Use for dataset landing pages so datasets are discoverable in Google Dataset Search with license, creator and download details. Dataset Open Discussion Forum Use for forum and community threads where a primary post and subsequent replies are publicly visible. DiscussionForumPosting Open Limited Education Q&A Use for educational question-answer pages where a single canonical answer and supporting context are visible. Quiz Open Employer Aggregate Rating Use on pages that publish employer rating aggregates from a clear and policy-compliant review source. EmployerAggregateRating Open Retired Estimated Salary Use for compensation insight pages that present transparent salary ranges for specific occupations and locations. Occupation Open Event Use for upcoming events with a real-world or virtual occurrence, schedule, and location context. Event Open Retired Fact Check Use for fact-checking pages that evaluate a specific claim with a transparent rating methodology. ClaimReview Open Retired Home Activities Use for virtual classes and activities where participation details and timing are clearly listed. Event Open Retired How-To Use for instructional content that teaches a process through ordered steps and actionable detail. HowTo Open Image Metadata Use on image pages and image hosts that expose ownership and licensing information to search engines. ImageObject Open Job Posting Use for active job listings that include role details, hiring entity, and location/salary context. JobPosting Open Retired Learning Video Use for educational videos where the learning objective and pedagogical structure are explicit. LearningResource Open Local Business Use for physical businesses serving local customers with publicly verifiable contact and location details. LocalBusiness Open Loyalty Program Use to publish a loyalty program and its tiers once at the organization level, so member prices and member shipping can reference them. MemberProgram Open Math Solvers Use for pages that solve mathematical expressions and present step-by-step computational guidance. MathSolver Open Merchant Listing Use on pages where a product can be bought, with price, availability, shipping and return details. Product Open Limited Movie Use for movie detail pages with canonical film information and transparent metadata attribution. Movie Open Organization Use for official organization pages to clarify brand identity and authoritative entity signals. Organization Open Retired Practice Problems Use for educational practice content that presents solvable problems and answer validation structure. Quiz Open Product Snippet Use for product pages where pricing, availability, and product identity are visible to users. Product Open Product Variants Use when one product comes in variants such as size or color, grouped with ProductGroup. ProductGroup Open Profile Page Use for creator or contributor profile pages where identity attributes and ownership are explicit. ProfilePage Open Q&A Use for pages where users submit questions and community or editorial answers are displayed. QAPage Open

Implement Recipe Schema Frameworks Correctly

Get implementation support for conditional schema architecture, validation, and deployment governance.