WordPress Themes

How to Build a WordPress Block Theme From Scratch

Build a block theme step by step: the required files, theme.json settings and styles, HTML templates and template parts, patterns, style variations and exporting from the Site Editor.

Block theme folder with theme.json, templates and parts beside the WordPress Site Editor showing the home template

A block theme is a WordPress theme built from HTML templates made of blocks, with design settings in theme.json, so the whole site (header, footer, templates) can be edited in the Site Editor. The minimum is style.css and templates/index.html; a real theme adds theme.json, template parts in parts/, more templates and patterns. You can build visually in the Site Editor and export the result to files with the Create Block Theme plugin.

The file structure

tle-blocks/
├── style.css
├── theme.json
├── functions.php        (optional)
├── screenshot.png
├── templates/
│   ├── index.html
│   ├── single.html
│   ├── page.html
│   ├── archive.html
│   ├── search.html
│   └── 404.html
├── parts/
│   ├── header.html
│   └── footer.html
├── patterns/
│   └── hero.php
└── styles/
    └── dark.json        (style variation)

Step 1: style.css

/*
Theme Name: TLE Blocks
Version: 1.0.0
Requires at least: 6.5
Requires PHP: 8.0
Text Domain: tle-blocks
License: GPL-2.0-or-later
*/

In a block theme this file mainly carries the header. Most styling moves into theme.json.

Step 2: theme.json

{
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 3,
  "settings": {
    "appearanceTools": true,
    "layout": { "contentSize": "720px", "wideSize": "1200px" },
    "color": {
      "palette": [
        { "slug": "base", "name": "Base", "color": "#ffffff" },
        { "slug": "contrast", "name": "Contrast", "color": "#0f172a" },
        { "slug": "primary", "name": "Primary", "color": "#16a34a" }
      ]
    },
    "typography": {
      "fluid": true,
      "fontSizes": [
        { "slug": "small", "name": "Small", "size": "0.9rem" },
        { "slug": "large", "name": "Large", "size": "1.5rem" }
      ]
    }
  },
  "styles": {
    "color": { "background": "var(--wp--preset--color--base)", "text": "var(--wp--preset--color--contrast)" },
    "elements": { "link": { "color": { "text": "var(--wp--preset--color--primary)" } } }
  },
  "templateParts": [
    { "name": "header", "area": "header", "title": "Header" },
    { "name": "footer", "area": "footer", "title": "Footer" }
  ]
}

Presets become CSS custom properties (--wp--preset--color--primary) and editor options. Every setting is explained in theme.json explained.

Step 3: Template parts

parts/header.html:

<!-- wp:group {"tagName":"header","layout":{"type":"flex","justifyContent":"space-between"}} -->
<header class="wp-block-group">
  <!-- wp:site-title /-->
  <!-- wp:navigation /-->
</header>
<!-- /wp:group -->

Step 4: Templates

templates/index.html:

<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} -->
<main class="wp-block-group">
  <!-- wp:query {"query":{"inherit":true}} -->
  <div class="wp-block-query">
    <!-- wp:post-template -->
      <!-- wp:post-title {"isLink":true} /-->
      <!-- wp:post-excerpt /-->
    <!-- /wp:post-template -->
    <!-- wp:query-pagination /-->
  </div>
  <!-- /wp:query -->
</main>
<!-- /wp:group -->
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->

"inherit": true makes the Query Loop use the page's main query, the block equivalent of the classic loop. Template names follow the same template hierarchy as classic themes.

Step 5: Build visually, then export

Writing block markup by hand is slow. A faster workflow:

  1. Activate your minimal theme.
  2. Design templates and parts in Appearance > Editor.
  3. Install the Create Block Theme plugin and save your changes back to the theme files.
  4. Commit the files to version control.

Changes made in the Site Editor are stored in the database and override theme files until exported or reset. Keep that in mind when deploying.

Step 6: Patterns

Files in patterns/ are registered automatically from their header:

<?php
/**
 * Title: Hero
 * Slug: tle-blocks/hero
 * Categories: featured
 */
?>
<!-- wp:cover {"dimRatio":60} --> ... <!-- /wp:cover -->

Using PHP files lets you translate strings and reference theme asset URLs. See block patterns.

Step 7: Style variations

JSON files in styles/ override parts of theme.json and appear as alternative looks under Styles in the Site Editor, for example a dark variation with a different palette.

Step 8: functions.php (optional)

Block themes need far less PHP, but functions.php is still the place to enqueue an extra stylesheet, register block styles, or register pattern categories.

Common mistakes

  • Editing templates in the Site Editor and forgetting they are now in the database, so file changes "do nothing".
  • Hard-coding colors and sizes in CSS instead of using theme.json presets.
  • Invalid block markup from hand-editing, which shows "block contains unexpected content".
  • Putting site functionality in the theme instead of a plugin.

Frequently asked questions

What is the minimum for a block theme?

style.css with a theme header and templates/index.html.

Do block themes need PHP?

Not necessarily. Templates are HTML, settings are JSON; functions.php and PHP patterns are optional.

Can I convert a classic theme to a block theme?

Yes, gradually: add theme.json first, then block template parts, then block templates. A hybrid stage is common.

How do I make a child theme of a block theme?

Add Template: to the child's style.css and override only the templates, parts or theme.json values you need. See block theme child themes.

Conclusion

Block themes move design into theme.json and markup into block templates, which makes them lighter and editable by site owners. Start minimal, design in the Site Editor, export to files and keep everything in version control. References: the Theme Handbook quick start and the global settings and styles guide.

Need a block theme designed and built for your brand? See our theme development service.

Save this practical guide

Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.

· Tutor LMS developers

Guides written and reviewed by the TutorLMS Expert development team. Every hook, function, table and setting we mention is checked against the Tutor LMS and Tutor LMS Pro source code before it is published.

Keep reading

Need a custom Tutor LMS solution?

Tell us what you are building or what is broken. A Tutor LMS developer reads every inquiry and replies with next steps and a free estimate.

Get a free Tutor LMS consultation

Tell us what you are building or fixing. A Tutor LMS developer replies with honest advice and next steps.

  • No obligation
  • Tutor LMS and Pro specialists
  • Your details stay private

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.