{"id":4854,"date":"2022-10-09T16:38:43","date_gmt":"2022-10-09T16:38:43","guid":{"rendered":"https:\/\/learncode.tinjurewp.com\/?p=4854"},"modified":"2023-01-11T18:04:43","modified_gmt":"2023-01-11T18:04:43","slug":"deep-diving-into-json-elements","status":"publish","type":"post","link":"https:\/\/learncode.tinjurewp.com\/deep-diving-into-json-elements\/","title":{"rendered":"Deep-diving Into JSON Elements"},"content":{"rendered":"<p class=\"note icon-note\">Notes: This post is <strong>part 1 <\/strong>of my proof-of-concepts learning note post for <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/\" target=\"_blank\" rel=\"noopener\">CSS-Tricks article<\/a> on the JSON elements. Some screenshot images used here are credited to the CSS-Tricks.<\/p>\n<p>There is considerable ongoing efforts in Gutenberg block editor to move the entire style definitions to a single place, i.e.\u00a0<code>theme.json<\/code>\u00a0file. To measure the progress, let&#8217;s look at the last three\u00a0<a href=\"https:\/\/github.com\/WordPress\/wordpress-develop\/tree\/trunk\/src\/wp-content\/themes\" target=\"_blank\" rel=\"noopener\">default themes<\/a>\u00a0(TT1, TT2, TT3).<\/p>\n<p>The TT1 theme, the first default theme designed for block editor, contains over\u00a0<a href=\"https:\/\/github.com\/WordPress\/wordpress-develop\/blob\/trunk\/src\/wp-content\/themes\/twentytwentyone\/style.css\" target=\"_blank\" rel=\"noopener\">5,900 lines of CSS<\/a>, a JavaScript file, and a &#8230; KB size. There is no\u00a0<code>theme.json<\/code>\u00a0file.<\/p>\n<p>The TT2, the first block-based default theme, which includes\u00a0<code>theme.json<\/code>\u00a0file and only over\u00a0<a href=\"https:\/\/github.com\/WordPress\/wordpress-develop\/blob\/trunk\/src\/wp-content\/themes\/twentytwentytwo\/style.css\" target=\"_blank\" rel=\"noopener\">147 lines of CSS<\/a>\u00a0code. The\u00a0<code>theme.json<\/code>\u00a0file contains only\u00a0<a href=\"https:\/\/github.com\/WordPress\/wordpress-develop\/blob\/trunk\/src\/wp-content\/themes\/twentytwentytwo\/theme.json\" target=\"_blank\" rel=\"noopener\">373 lines<\/a>. Its lead developers had made concerted efforts to make this as the CSS-less theme, however, at that time not all CSS styling rules via\u00a0<code>theme.json<\/code> were resolved in Gutenberg site editor. If we look at the TT2 CSS file, those issues included, styling of (i) links and their interactive state, (ii) consistency in styling buttons, and spacing and full-width (age-to-edge) layout.<\/p>\n<p>Now that these styling CSS issues have now been resolved and thus the TT3 is the first default theme, without a single line of theme CSS. It&#8217;s <code>theme.json<\/code>\u00a0file contains\u00a0<a href=\"https:\/\/github.com\/WordPress\/twentytwentythree\/blob\/trunk\/theme.json\" target=\"_blank\" rel=\"noopener\">687 lines<\/a> of codes. The theme is slim down version of TT2 with added &#8230; styles alternatives and has ..KB file size.<\/p>\n<p>At present, not all the CSS styling rules via\u00a0<code>theme.json<\/code>\u00a0has been resolved, and the remaining significant issues are currently being discussed with an aim to fully move all the CSS style rules into the <code>theme.json<\/code> and consolidate different sources of\u00a0<code>theme.json<\/code> into a single Global Style UI via <a href=\"https:\/\/developer.wordpress.org\/block-editor\/reference-guides\/packages\/packages-style-engine\/\" target=\"_blank\" rel=\"noopener\">Style Engine<\/a> and create front-end CSS.<\/p>\n<p>These new developmental features included in WordPress 6.1 have not been widely exposed to most WordPress users due to lack to documentations, notes and tutorials.\u00a0In this article, I attempt to share my current understanding of these new features with you with some use case examples.<\/p>\n<div class=\"article-series\"><strong>Learning Goals<\/strong><br \/>\n<strong>Part 1<\/strong>: JSON elements API &#8211; An Introduction and Overview (<strong>this post<\/strong>)<br \/>\nPart 2: Using JSON Elements<\/div>\n<p>The objective of this learning-note post series is to document my research on the topic and retain my memory dump, while preparing a first draft of my article for the CSS-Tricks.<\/p>\n<p>First off, let&#8217;s briefly overview JSON element and Pseudo-classes interactive states.<\/p>\n<h6><strong>An Overview<\/strong><\/h6>\n<p>One of the main goals of the Gutenberg site editor is to absorb the entire CSS of classic themes by\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/08\/01\/moving-core-block-styling-to-json\/#comment-43544\">moving theme CSS to theme JSON file<\/a>. This approach creates different layers of theme JSON files (e.g., Core, block, theme, and user), and thus introduces a new specificity or precedence issue for theme developers.<\/p>\n<p>Since the\u00a0<a href=\"https:\/\/developer.wordpress.org\/block-editor\/how-to-guides\/themes\/block-theme-overview\/\">block themes<\/a>\u00a0were introduced in\u00a0<a href=\"https:\/\/wordpress.org\/news\/2022\/01\/josephine\/\">WordPress 5.9<\/a>,\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/04\/13\/core-styles-and-theme-customization-the-next-steps\/\">how to override Core generated CSS<\/a>\u00a0has been one of the main concerns. This problem has been further exacerbated by the frequency of the Gutenberg plugin release cycles, often with moving targets, which are eloquently described in this\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/04\/13\/core-styles-and-theme-customization-the-next-steps\/\">Make WordPress post<\/a>.<\/p>\n<h6>Theme JSON and theme CSS<\/h6>\n<p>Though structurally, both the\u00a0<code>theme.json<\/code>\u00a0and theme CSS look similar. In block themes,\u00a0<code>theme.json<\/code>\u00a0provides a single place to configure and customize its styling.<\/p>\n<p>In this\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/08\/01\/moving-core-block-styling-to-json\/#comment-43544\">Make WordPress Core blog proposal<\/a>, Ben Dwyer of Gutenberg development team, eloquently articulates the reasoning of moving the theme CSS into the\u00a0<code>theme.json<\/code>\u00a0file, and its benefit to block theme authors.<\/p>\n<p>One of the major benefits of moving CSS to JSON is that the latter is machine-readable format, and can be exposed in site editor UI, thus allowing users to modify default values and customize the site appearance without writing CSS. It also provides access to block style consistency and better style hierarchy settings, such that the user&#8217;s settings take the highest priority over the theme provided\u00a0<code>theme. json<\/code>\u00a0settings.<\/p>\n<p>For theme authors, the\u00a0<code>theme.json<\/code>\u00a0provides options to define most block styles within JSON. Theme users would be able change the site&#8217;s default visual appearance by using the\u00a0<a href=\"https:\/\/wordpress.org\/support\/article\/styles-overview\/\">Global Styles interface<\/a>, without writing CSS.<\/p>\n<p>You can find more detail behind the scene <a href=\"https:\/\/make.wordpress.org\/core\/2022\/08\/01\/moving-core-block-styling-to-json\/#comment-43544\" target=\"_blank\" rel=\"noopener\">discussion<\/a> notes from the <a href=\"https:\/\/make.wordpress.org\/core\/2022\/08\/01\/moving-core-block-styling-to-json\/#comment-43544\" target=\"_blank\" rel=\"noopener\">Make WordPress Core post<\/a>.<\/p>\n<h6><strong>HTML element vs JSON Element<\/strong><\/h6>\n<p>The <em>MDN glossary describes<\/em> <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Element\" target=\"_blank\" rel=\"noopener\">elements<\/a> as \u201ca part of a webpage. In <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/XML\" target=\"_blank\" rel=\"noopener\">XML<\/a> and <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/HTML\" target=\"_blank\" rel=\"noopener\">HTML<\/a>, an element may contain a data item or a chunk of text or an image, or perhaps nothing. A typical element includes an opening tag with some <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Glossary\/Attribute\" target=\"_blank\" rel=\"noopener\">attributes<\/a>, enclosed text content, and a closing tag.\u201d<\/p>\n<p>This <a href=\"https:\/\/fullsiteediting.com\/lessons\/theme-json-elements\/\">Full Site Editing tutorial<\/a> explains why there are essential with a table of Gutenberg and WordPress supported selectors.<\/p>\n<h6>JSON elements<\/h6>\n<p>Previously, only individual heading and link elements were available (e.g., see this sample from\u00a0<a href=\"https:\/\/github.com\/WordPress\/twentytwentytwo\/blob\/trunk\/theme.json#L268-L324\">TT2 theme<\/a>). Now, with WordPress 6.1, we can also\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/10\/10\/styling-elements-in-block-themes\/\">add<\/a>\u00a0Button, Caption, Cite, and Headings element to the\u00a0<code>theme json<\/code>\u00a0file to address the issues of inconsistent style of similar elements across blocks.<\/p>\n<p>JSON\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/08\/01\/moving-core-block-styling-to-json\/\">elements<\/a>\u00a0are low-level components for themes and blocks, that do not need the complexity of blocks. They are a\u00a0<a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/40966\">representation of HTML primitives<\/a>\u00a0which are currently not within any block and can be used across blocks. How they are supported in the WordPress and Gutenberg is described in the\u00a0<a href=\"https:\/\/developer.wordpress.org\/block-editor\/how-to-guides\/themes\/theme-json\/#element-styles\">Editor Handbook<\/a>\u00a0and this\u00a0<a href=\"https:\/\/fullsiteediting.com\/lessons\/theme-json-elements\/\">Full Site Editing tutorial<\/a>.<\/p>\n<p>For example, the links are found in lots of blocks but do not have their own block. By the same token, headings and buttons have their-own blocks, but they are also used across many other blocks as well. Similarly, HTML headings, button, caption, form, and cite elements are also used within the blocks.<\/p>\n<p>A few properties of the JSON elements include:<\/p>\n<ul>\n<li>Elements are simpler than blocks<\/li>\n<li>They may be shared across the blocks (e.g., buttons rules for file, search, and button blocks)<\/li>\n<li>Elements can be styled uniformly regardless of the block to which they belong. Examples, buttons, and forms field.<\/li>\n<li>Elements have\u00a0<a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/40966#issue-1231181876\">lower specificity than then the blocks<\/a>.<\/li>\n<\/ul>\n<p>While these different layers of\u00a0<code>theme.json<\/code>\u00a0files create a new specific problem, the problem should be solved with the Style Engine API.<\/p>\n<p>The\u00a0<a href=\"https:\/\/developer.wordpress.org\/block-editor\/how-to-guides\/themes\/theme-json\/#element-styles\">JASON elements are styled<\/a>\u00a0at both the upper level (Global) and at the block level. On the top level, they are used with an element selector, and at the block level, the element to be used will be &#8220;the element added to the corresponding block&#8221;.<\/p>\n<h6>Elements style in <code>theme.json<\/code> and via Editor UI<\/h6>\n<p>Prior to WordPress 6.1, elements available in Global Styles UI were limited to<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">{\n  &quot;version&quot;: 2,\n  &quot;settings&quot;: {},\n    ...\n    ...\n  &quot;styles&quot;: {\n    ...\n    ...\n    &quot;elements&quot;: {\n        &quot;h1&quot;: {\n          &quot;typography&quot;: { }\n        },\n        ...\n        ...\n        &quot;h6&quot;: {\n          &quot;typography&quot;: { }\n        },\n        &quot;link&quot;: {\n          &quot;color&quot;: {\n            &quot;text&quot;: &quot;var(--wp--preset--color--foreground)&quot;\n          }\n        }\n    },\n    ...\n    ...\n  },\n  &quot;templateParts&quot;: {}\n}<\/code><\/pre>\n<p>The following screenshot shows how typography and color styling can be customized using Global Styles Interface.<\/p>\n<figure id=\"attachment_2762\" aria-describedby=\"caption-attachment-2762\" style=\"width: 990px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2762 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/6.0.2-global-ui.png\" alt=\"\" width=\"990\" height=\"381\" \/><figcaption id=\"caption-attachment-2762\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2762 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/6.0.2-global-ui.png\" alt=\"\" width=\"990\" height=\"381\" \/><\/noscript> Screenshot showing Global Styles UI for typography and color styling customization in WordPress 6.0.2<\/figcaption><\/figure>\n<p>In WordPress 6.1 new elements have been added. The following partial <code>theme.json<\/code> example from TTT3 theme<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">{\n  &quot;version&quot;: 2,\n  &quot;settings&quot;: {},\n    ...\n    ...\n  &quot;styles&quot;: {\n    ...\n    ...\n    &quot;elements&quot;: {\n\t&quot;button&quot;: {\n\t\t&quot;border&quot;: {\n\t\t\t&quot;radius&quot;: &quot;0&quot;\n\t\t},\n\t\t&quot;color&quot;: {\n\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--primary)&quot;,\n\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n\t\t},\n\t\t&quot;:hover&quot;: {\n\t\t\t&quot;color&quot;: {\n\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--contrast)&quot;,\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t}\n\t\t},\n\t\t&quot;:focus&quot;: {\n\t\t\t&quot;color&quot;: {\n\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--contrast)&quot;,\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t}\n\t\t},\n\t\t&quot;:active&quot;: {\n\t\t\t&quot;color&quot;: {\n\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--secondary)&quot;,\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t}\n\t\t}\n\t},\n\t&quot;h1&quot;: {\n\t\t&quot;typography&quot;: { }\t\t\n\t},\n\t&quot;h2&quot;: {\n\t\t&quot;typography&quot;: { }\t\n\t},\n\t...\n        ...\n\t&quot;h6&quot;: {\n\t\t&quot;typography&quot;: { }\t\n\t},\n\t&quot;heading&quot;: {\n\t\t&quot;typography&quot;: {\n\t\t\t&quot;fontWeight&quot;: &quot;400&quot;,\n\t\t\t&quot;lineHeight&quot;: &quot;1.4&quot;\n\t\t}\n\t},\n\t&quot;link&quot;: {\n\t\t&quot;color&quot;: {\n\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n\t\t},\n\t\t&quot;:hover&quot;: {\n\t\t\t&quot;typography&quot;: {\n\t\t\t\t&quot;textDecoration&quot;: &quot;none&quot;\n\t\t\t}\n\t\t},\n\t\t&quot;:focus&quot;: {\n\t\t\t&quot;typography&quot;: {\n\t\t\t\t&quot;textDecoration&quot;: &quot;underline dashed&quot;\n\t\t\t}\n\t\t},\n\t\t&quot;:active&quot;: {\n\t\t\t&quot;color&quot;: {\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--secondary)&quot;\n\t\t\t},\n\t\t\t&quot;typography&quot;: {\n\t\t\t\t&quot;textDecoration&quot;: &quot;none&quot;\n\t\t\t}\n\t\t},\n\t\t&quot;typography&quot;: {\n\t\t\t&quot;textDecoration&quot;: &quot;underline&quot;\n\t\t}\n\t}\n   },\n    ...\n    ...\n  },\n  &quot;templateParts&quot;: {}\n}<\/code><\/pre>\n<p>This allows to expose element JSON styles into editor &gt; Global styles UI<\/p>\n<figure id=\"attachment_2760\" aria-describedby=\"caption-attachment-2760\" style=\"width: 664px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2760 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/6.1-global-typography-ui.png\" alt=\"\" width=\"664\" height=\"521\" \/><figcaption id=\"caption-attachment-2760\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2760 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/6.1-global-typography-ui.png\" alt=\"\" width=\"664\" height=\"521\" \/><\/noscript> Screenshot showing global typography elements in WordPress 6.1.<\/figcaption><\/figure>\n<p>For example, changing buttons and links color styles can be customized directly on the Global Styles interface.<\/p>\n<figure id=\"attachment_2761\" aria-describedby=\"caption-attachment-2761\" style=\"width: 872px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2761 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/6.1-global-color-ui.png\" alt=\"\" width=\"872\" height=\"555\" \/><figcaption id=\"caption-attachment-2761\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2761 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/6.1-global-color-ui.png\" alt=\"\" width=\"872\" height=\"555\" \/><\/noscript> Screenshot showing global links and button elements styling colors options in WordPress 6.1<\/figcaption><\/figure>\n<p><em>Benefits<\/em><\/p>\n<p>One of the benefit of this approach is that theme developers start using <code>block.json<\/code> file which can be overridden by <code>theme.json<\/code> file without using CSS. Users can modify these features using editor Global Styles UI.<\/p>\n<p>Simple themes may be replaced all CSS (eg. TT3, and few others), but more complex and advanced block themes still need provide their own CSS.<\/p>\n<p><em>How to use?<\/em><\/p>\n<p>Theme.json can be used at: \u2013 block-level: (define &amp; example) Elements styles within a block are more specific and applies to with a specific block only. Any user modifications applied to Global Styles UI are not applied because of their higher specificity abut only modifications made for the particular block. Eg: coloring search or download buttons differently than rest of the buttons in a site.<\/p>\n<ul>\n<li>Elements within blocks (define and example): Applies to a specific block throughout the site (eg. Color within a search block)<\/li>\n<li>Globally elements shared by blocks (define &amp; example) This applies to all instances of elements and applies to across the blocks (eg. Buttons, links)<\/li>\n<\/ul>\n<p>Additional information on JSON elements is available in\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/08\/01\/moving-core-block-styling-to-json\/\">this Make WordPress proposal<\/a>\u00a0and\u00a0<a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/40966\">this GitHub ticket<\/a>.<\/p>\n<p>An use case example using <a href=\"https:\/\/github.com\/WordPress\/theme-experiments\/tree\/master\/emptytheme\">Emptytheme<\/a>, a blank theme with no style, is described in <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-global-styles-for-json-elements\" target=\"_blank\" rel=\"noopener\">this section of the CSS-Tricks article<\/a>.<\/p>\n<h6>Style precedence<\/h6>\n<p>To overview and get a feel of how specificity works, let&#8217;s look the following example of styling a button block.<\/p>\n<p><strong>Rule 1<\/strong>: Site editor&#8217;s core <code>theme.json<\/code> file provides basic default styles.<\/p>\n<p>Let&#8217;s start with the <a href=\"https:\/\/github.com\/WordPress\/theme-experiments\/tree\/master\/emptytheme\">Emptytheme<\/a>, a blank theme with no style, add a button block in a new page. In the example below, the black background color and rounded style rules were applied from the editor&#8217;s default settings.<\/p>\n<figure id=\"attachment_4905\" aria-describedby=\"caption-attachment-4905\" style=\"width: 768px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-4905 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-empty-768x79-1.png\" alt=\"\" width=\"768\" height=\"79\" \/><figcaption id=\"caption-attachment-4905\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-4905 lazyload\" src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-empty-768x79-1.png\" alt=\"\" width=\"768\" height=\"79\" srcset=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-empty-768x79-1.png 768w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-empty-768x79-1-300x31.png 300w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-empty-768x79-1-200x21.png 200w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/noscript> Screenshot showing a button with default (core) style. (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-json-and-css-specificity\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<p><strong>Rule 2<\/strong>: The block theme&#8217;s <code>theme.json<\/code> settings take priority over the core default settings.<\/p>\n<p>Let&#8217;s change our theme to TT3 and activate it and if we check the same button block, it looks rectangular with lemon background color.<\/p>\n<figure id=\"attachment_4906\" aria-describedby=\"caption-attachment-4906\" style=\"width: 768px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-4906 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-tt3-global-768x79-1.png\" alt=\"\" width=\"768\" height=\"79\" \/><figcaption id=\"caption-attachment-4906\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-4906 lazyload\" src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-tt3-global-768x79-1.png\" alt=\"\" width=\"768\" height=\"79\" srcset=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-tt3-global-768x79-1.png 768w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-tt3-global-768x79-1-300x31.png 300w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/button-tt3-global-768x79-1-200x21.png 200w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/noscript> Screenshot showing with TT3 theme global style. (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-json-and-css-specificity\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<p>You will notice, the TT3 global button element style (<a href=\"https:\/\/github.com\/WordPress\/twentytwentythree\/blob\/trunk\/theme.json#L598-L625\" target=\"_blank\" rel=\"noopener\">code snippet here<\/a>) took the precedence over core&#8217;s <code>theme.json<\/code> styling.<\/p>\n<p><strong>Rule 3<\/strong>: Elements styles within a block are more specific than the theme&#8217;s settings.<\/p>\n<p>In the next example, I am using a modified TT3-child theme, where default background color of buttons block are set to red.<\/p>\n<figure id=\"attachment_4907\" aria-describedby=\"caption-attachment-4907\" style=\"width: 768px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-4907 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/search-button-tt3-child-768x271-1.png\" alt=\"\" width=\"768\" height=\"271\" \/><figcaption id=\"caption-attachment-4907\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-4907 lazyload\" src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/search-button-tt3-child-768x271-1.png\" alt=\"\" width=\"768\" height=\"271\" srcset=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/search-button-tt3-child-768x271-1.png 768w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/search-button-tt3-child-768x271-1-300x106.png 300w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/search-button-tt3-child-768x271-1-200x71.png 200w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/noscript> Screenshot showing style precedence with block-level element styling. (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-json-and-css-specificity\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<p>In the screenshot shown above, all buttons are styled with default state red color at the global-level, however only its search button is modified to use TT3&#8217;s default lemon green color.<\/p>\n<p><strong>Rule 4<\/strong>: Custom user styles from Global Styles UI take the highest level of precedence.<\/p>\n<p>Next, change the red background color on the buttons block and the lime green color on the search button with the help of the Global Styles interface.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-4908 aligncenter lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/user-customized-button-768x538-1.png\" alt=\"\" width=\"768\" height=\"538\" \/><noscript><img decoding=\"async\" class=\"size-full wp-image-4908 aligncenter lazyload\" src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/user-customized-button-768x538-1.png\" alt=\"\" width=\"768\" height=\"538\" srcset=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/user-customized-button-768x538-1.png 768w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/user-customized-button-768x538-1-300x210.png 300w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/10\/user-customized-button-768x538-1-200x140.png 200w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/noscript><\/p>\n<p>In the screenshot above, the frontend view shows that the button background is changes to <em>Vivid cyan blue<\/em> while the background of the search button to <em>Vivid red,<\/em> with the highest priority.<\/p>\n<h6>Style engine<\/h6>\n<p>Since the introduction of the block themes in WordPress 5.9, overriding Gutenberg generated different layers of CSS has been a major issue, which is eloquently described in\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/04\/13\/core-styles-and-theme-customization-the-next-steps\/\">this Make WordPress post<\/a>.<\/p>\n<blockquote><p>Overriding CSS, whether layout, preset, or block styles, presents an obstacle to integration and interoperability: visual parity between the frontend and editor becomes more difficult to maintain, upgrades to block internals may conflict with overrides. Custom CSS is, furthermore, less portable across other block themes.<\/p>\n<p><a href=\"https:\/\/make.wordpress.org\/core\/2022\/04\/13\/core-styles-and-theme-customization-the-next-steps\/\">&#8211; Make WordPress Core Blog<\/a><\/p><\/blockquote>\n<p>To address these problems, a new\u00a0<a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/38167\">Style Engine<\/a>\u00a0has been introduced in\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/10\/10\/block-styles-generation-style-engine\/\">WordPress 6.1<\/a>\u00a0to &#8220;<em>provide a single, centralized agent responsible for generating and rendering consistent block supports styles on the client-side and server-side<\/em>\u201d. As of WordPress 6.1, key improvement to generate core\u00a0<a href=\"https:\/\/developer.wordpress.org\/block-editor\/reference-guides\/block-api\/block-supports\/\">block support<\/a>\u00a0for border, color, spacing, typography, and layout styles in the editor and frontend.<\/p>\n<p>Further details on long-term and short-term goals of addressing challenges to generate consistent styling and behind the scene discussion can be found here on\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/06\/24\/block-editor-styles-initiatives-and-goals\/\">Block editor styles: initiatives and goals<\/a>, with a more\u00a0<a href=\"https:\/\/make.wordpress.org\/core\/2022\/04\/13\/core-styles-and-theme-customization-the-next-steps\/\">recent update<\/a>. To find out more about Style Engine initiatives, please follow the\u00a0<a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/38167\">tracking issue<\/a>\u00a0and\u00a0<a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/38167\">project board<\/a>.<\/p>\n<h6>Useful Resources<\/h6>\n<p>The following is list of references link that I gathered during my brief research. While preparing this post, I have also referred some of the following references extensively.<\/p>\n<p><em>Element API<\/em><\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/WordPress\/gutenberg\/pull\/41753\" target=\"_blank\" rel=\"noopener\">Elements API<\/a> (GitHub)<\/li>\n<li><a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/41232\" target=\"_blank\" rel=\"noopener\">Global Styles Ongoing Roadmap #41232<\/a> ()<\/li>\n<li><a href=\"https:\/\/github.com\/WordPress\/gutenberg\/issues\/40966\" target=\"_blank\" rel=\"noopener\">Global Styles: Elements support tracking issue #40966<\/a> ()<\/li>\n<li><a href=\"https:\/\/fullsiteediting.com\/lessons\/theme-json-elements\/\" target=\"_blank\" rel=\"noopener\">Theme.json elements<\/a> (Full Site Editing)<\/li>\n<li><a href=\"https:\/\/developer.wordpress.org\/block-editor\/how-to-guides\/themes\/theme-json\/#element-styles\" target=\"_blank\" rel=\"noopener\">Elements styles<\/a> (Block Editor Handbook)<\/li>\n<\/ul>\n<p><em>Style Engine<\/em><\/p>\n<ul>\n<li><a href=\"https:\/\/make.wordpress.org\/core\/2022\/06\/24\/block-editor-styles-initiatives-and-goals\/\" target=\"_blank\" rel=\"noopener\">Block editor styles: initiatives and goals<\/a> (Make WordPress Blog)<\/li>\n<li><a href=\"https:\/\/make.wordpress.org\/core\/?p=99063&amp;preview=1&amp;_ppp=10ef94cb0b\" target=\"_blank\" rel=\"noopener\">Dev note: block styles generation (Style Engine)<\/a> (WordPress 6.1 Dev Notes) &#8212; needs UPDATE<\/li>\n<li><a href=\"https:\/\/make.wordpress.org\/core\/2022\/04\/13\/core-styles-and-theme-customization-the-next-steps\/\">Core Styles and Theme Customization: the next steps<\/a> (Make WordPress Blog)<\/li>\n<\/ul>\n<p><em>Pseudoclass and Pseudoelements<\/em><\/p>\n<ul>\n<li><a href=\"https:\/\/www.youtube.com\/watch?v=XikXzLLojhk\" target=\"_blank\" rel=\"noopener\">Setting Hover &amp; Focus States in Theme JSON and Global Styles!<\/a> (YouTube)<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn\/CSS\/Building_blocks\/Selectors\/Pseudo-classes_and_pseudo-elements\">Pseudo-classes and pseudo-elements<\/a> (MDN Web Docs)<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Pseudo-classes\">Pseudo-classes<\/a>\u00a0(MDN Web Docs)<\/li>\n<li><a href=\"https:\/\/github.com\/WordPress\/gutenberg\/pull\/41976\">Add link element :hover interactivity control to global styles UI #41976<\/a>(GitHub)<\/li>\n<li><a href=\"https:\/\/github.com\/WordPress\/gutenberg\/pull\/41786\">Support pseudo selectors on elements in theme json #41786\u00a0\u00a0<\/a>(GitHub)<\/li>\n<li><a href=\"https:\/\/make.wordpress.org\/core\/2022\/08\/01\/moving-core-block-styling-to-json\/\">Moving Core block styling to JSON<\/a>\u00a0(WordPress Core)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Notes: This post is part 1 of my proof-of-concepts learning note post for CSS-Tricks article on the JSON elements. Some screenshot images used here are credited to the CSS-Tricks. There is considerable ongoing efforts in Gutenberg block editor to move the entire style definitions to a single place, i.e.\u00a0theme.json\u00a0file. To measure the progress, let&#8217;s look [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[27],"tags":[],"class_list":["post-4854","post","type-post","status-publish","format-standard","hentry","category-full-site-editing"],"_links":{"self":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/4854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/comments?post=4854"}],"version-history":[{"count":0,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/4854\/revisions"}],"wp:attachment":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/media?parent=4854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/categories?post=4854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/tags?post=4854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}