Drupal 12 core has two themes you can use as they are – Default Admin for the admin and Stark, a bare theme for testing – and one you are meant to copy: Starterkit. Olivero, the default front-end theme of recent Drupal versions, has left core and continues as a contributed project. For a new site, the normal path is to generate your own theme from Starterkit.
Why generate instead of sub-theme
For years, Drupal themes were built as sub-themes of Classy or Stable, inheriting their templates. The problem was that every change in the base theme could change your site. Starterkit works the other way round: it copies its templates, CSS and libraries into your theme once. After that, your theme stands on its own (base theme: false) and core updates do not change its markup.
Generate the theme
Run this from the project root:
vendor/bin/dr generate-theme my_theme \
--name "My theme" \
--description "The front-end theme for my site" \
--path themes/custom
The machine name (my_theme) must be lowercase with underscores. --path is relative to the web root. You can also use another theme as the starting point with --starterkit, if that theme is marked as a starterkit. Then enable it and make it the default:
vendor/bin/dr en my_theme
vendor/bin/drush config:set system.theme default my_theme
(Or do the second step under Appearance.)
What you get
my_theme.info.yml– name,base theme: false, the libraries the theme loads and which core libraries it extends.my_theme.libraries.yml– the theme's CSS and JavaScript.templates/– Twig templates sorted into folders: block, content, content-edit, dataset, field, form, layout, misc, navigation, user and views.css/– the CSS that goes with the templates. It is deliberately plain; it is there so the site works, not so it looks finished.
Delete what you do not need. Every template you keep is one you maintain.
Regions
If you do not list any regions in .info.yml, the theme gets Drupal's default set (header, primary menu, secondary menu, highlighted, help, content, sidebar first, sidebar second, footer and a few more). Most sites want their own:
regions:
header: Header
primary_menu: 'Primary menu'
content: Content
footer: Footer
Remember to place blocks in the new regions under Structure → Block layout. When you enable a new theme, Drupal copies the block placement from the current default theme – on a fresh Drupal 12 site that is Default Admin, which can leave you with blocks you did not want, such as a login form. Check the block layout right after you switch.
Finding the right template
Turn on Twig debugging under Configuration → Development → Development settings (/admin/config/development/settings). The page source then shows, for every piece of output, which template is used and which file names you can create to override it, for example node--article--teaser.html.twig. Turn it off again on live sites.
Components
Single Directory Components (SDC) are part of core's theme system: a component is a folder in your theme's components/ folder with a .component.yml file, a Twig template and, if needed, CSS and JavaScript that are loaded only when the component is used. Core's own Navigation module is built this way – its components folder has a badge, a message, a title and a toolbar button. In Drupal 12 the old separate sdc module is removed; components need no module.
components/
card/
card.component.yml
card.twig
card.css
In a template, include a component by its theme and name: {{ include('my_theme:card', { title: label }) }}.
Hooks in themes
Preprocess functions and other hooks used to live in my_theme.theme. Since Drupal 11.5 the .theme file is deprecated, and hooks go into classes under src/Hook/ – core's own Default Admin theme has no .theme file at all, only hook classes. See Hooks in Drupal 12.
Front-end libraries in Drupal 12
If your theme uses JavaScript from core, note the new major versions: jQuery 4, HTMX 4 and CKEditor 5 version 49. Backbone and Underscore are no longer in core. Code that depends on them needs to bring its own copy or be rewritten. See What is new in Drupal 12.