page.html
header

Global styles – theme.json

A theme’s global styles are defined in a file called theme.json.

It’s a complicated file in JavaScript Object Notation (JSON ) format.

  • There are many settings which can have lots of values.
  • You have to get the structure and the syntax correct.
  • If you make any mistake with the syntax then the Global Styles aren’t set.
  • You don’t get any messages.
  • Everything just looks all wrong.
  • If you do make any changes, use a JSON validator to check your syntax.
  • And then check it again for semantics.

The level 1 parts of the theme.json file are:

{
        "version": 1,
        "settings": {},
        "styles": {},
        "customTemplates": {},
        "templateParts": {}
}
version section of theme.json
Level 1Level 2Level 3Level 4Values
settings
bordercustomColor, customRadius, customStyle, customWidth true / false
colorcustom, customGradient, duotone, gradients, link, palette
spacingcustomPaddingtrue / false
units[ px, em, rem, vh, vw ]
typography
customFontSizetrue / false
customFontWeighttrue / false
customFontStyletrue / false
customLineHeighttrue / false
dropCaptrue / false
fontFamilies[ fontFamily, slug ]
fontSizes[ name,size,slug ]
layout
contentSizeeg 800px
wideSizeeg 1200px
customeg line-heighteg body, heading
blocksblockname eg core/paragraphborder,color,custom,layout,spacing,typographyas for level2
settings section of theme.json
Level 1Level 2Level 3Level 4Values
styles
bordercolor, radius, style, width value
color
background var( –wp–preset–color–background )
gradient
text var( –wp–preset–color–foreground )
spacingpaddingtop, right, bottom, leftvalue
typography
fontFamilyvalue
fontSizevalue
fontStylevalue
fontWeightvalue
lineHeightvalue
textDecorationvalue
textTransformvalue
elements
linkborder, color, spacing, typography
element name eg h1
blocksblock name eg core/groupborder, color, spacing, typography, elementsas for level 2
as for root
style section of theme.json
Level 1 Level 2Level 3Level 4Values
customTemplates[]
nameeg single-full
titleeg Full width stuff
postTypes[]page, post, CPT
customTemplates section of theme.json
Level 1 Level 2Level 3Level 4Values
templateParts[]
nameeg header
areaeg header
templateParts section of theme.json

The theme.json file uses settings to define the options that are supported in the editor, and styles to set default values and/or override the setttings at a global level.

The Site Editor Global styles panel defines the user’s modification to the global styles set by the theme.

Each block can be individually customised, depending on the options presented.

Examples

Typography

The Global Styles Root panel shows the defaults for all blocks.

Typography controls include:

  • Font family – styles.typography.fontFamily
  • Font size – styles.typography.fontSize
  • Line height (not shown) – styles.typography.lineHeight
  • Appearance – styles.typography.fontWeight

Styling header, footer and other areas

I don’t know how to do this using theme.json.

References

For details of how the values defined in theme.json work together to define the settings of the block editor see

Block Editor Handbook: Global Settings (theme.json ), the source of which is

https://github.com/WordPress/gutenberg/blob/trunk/docs/how-to-guides/themes/theme-json.md

JSONLint – the JSON validator

https://make.wordpress.org/design/handbook/focuses/global-styles/

Navigation

Page List

Page Tree ( shortcode )

© Copyright Herb Miller, Bobbing Wide 2021