{"id":4857,"date":"2022-12-08T16:56:24","date_gmt":"2022-12-08T16:56:24","guid":{"rendered":"https:\/\/learncode.tinjurewp.com\/?p=4857"},"modified":"2023-01-15T10:45:12","modified_gmt":"2023-01-15T10:45:12","slug":"part-2-json-elements-using-json-elements","status":"publish","type":"post","link":"https:\/\/learncode.tinjurewp.com\/part-2-json-elements-using-json-elements\/","title":{"rendered":"Part 2: JSON Elements: Using JSON Elements"},"content":{"rendered":"<p class=\"note icon-note\">Notes: This post is <strong>part 2 <\/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>In the previous section, we briefly overview the <a href=\"https:\/\/developer.wordpress.org\/block-editor\/how-to-guides\/themes\/theme-json\/#element-styles\" target=\"_blank\" rel=\"noopener\">JASON elements<\/a> and discussed how they are used in a <code>theme.json<\/code> file. In this section, let&#8217;s expand JSON elements use cases at both the top-level (Global) and block-level. At the top-level, they are used using an element selector, and at the block-level, the element to used will be &#8220;the element\u2019s appended to the corresponding block&#8221;.<\/p>\n<div class=\"article-series\"><strong>Learning Goals<\/strong><br \/>\nPart 1: JSON elements API &#8211; An Introduction and Overview<br \/>\n<strong>Part 2<\/strong>:Using JSON Elements (<strong>this post<\/strong>)<\/div>\n<p>In this section, lets look at briefly how JSON styles are used in top (global) label and block level.<!--more--><\/p>\n<h6>Styling elements globally<\/h6>\n<p>Let&#8217;s look at the new default TT3 theme and examine how its buttons elements are styled. The following is the slim-down <code>theme.json<\/code> file of the TT3 theme showing the global elements styles section, but you can find the <a href=\"https:\/\/github.com\/WordPress\/twentytwentythree\/blob\/trunk\/theme.json#L598-L666\">original code here<\/a>.<\/p>\n<p>In the TT3 theme,\u00a0 all buttons are styled at the <a href=\"https:\/\/github.com\/WordPress\/twentytwentythree\/blob\/trunk\/theme.json#L598-L625\" target=\"_blank\" rel=\"noopener\">top<\/a> (global) level. The following screenshot shows how different button blocks (default <em>button<\/em>, <em>Search<\/em>, <em>File<\/em>, and <em>Comments<\/em>) look uniform with similar lime green (primary, hex: <span class=\"pl-s\"><code>#9DFF20<\/code><\/span>) background color.<\/p>\n<figure id=\"attachment_2766\" aria-describedby=\"caption-attachment-2766\" style=\"width: 787px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2766 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/tt3-button-default.png\" alt=\"\" width=\"787\" height=\"554\" \/><figcaption id=\"caption-attachment-2766\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2766 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/tt3-button-default.png\" alt=\"\" width=\"787\" height=\"554\" \/><\/noscript> Screenshot showing default state green background color of buttons in TT3 theme. (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-global-styles-for-json-elements\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<p>If we examine their HTML and styling, a <code>wp-element-button<\/code> class is used for the styling. The same <code>wp-element-button<\/code> class is used to add its interactive states as well.<\/p>\n<figure id=\"attachment_2767\" aria-describedby=\"caption-attachment-2767\" style=\"width: 972px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-2767 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/fedault-tt3-button-2.png\" alt=\"\" width=\"972\" height=\"240\" \/><figcaption id=\"caption-attachment-2767\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2767 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/fedault-tt3-button-2.png\" alt=\"\" width=\"972\" height=\"240\" \/><\/noscript> Screenshot showing button block HTML (left) and its styling with <code>.wp-element-button<\/code> class. (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-global-styles-for-json-elements\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<h6>Adding interactive states<\/h6>\n<p>The WordPress 6.1 has added <a href=\"https:\/\/make.wordpress.org\/core\/2022\/10\/10\/styling-elements-in-block-themes\/\" target=\"_blank\" rel=\"noopener\">support for defining interactivity states<\/a> &#8220;pseudo classes&#8221; (e.g. <code>:hover<\/code>, <code>:focus<\/code>) in <code>theme.json<\/code> as well as in Global Styles UI for a limited set of elements.<\/p>\n<p>For a refresher, the following short <a href=\"https:\/\/www.youtube.com\/watch?v=XikXzLLojhk\" target=\"_blank\" rel=\"noopener\">YouTube video<\/a> by Automattic Engineer Dave Smith, demonstrates how interactivity states are defined in <code>theme.json<\/code> and exposed to Global Styles UI.<\/p>\n<p><iframe class=\"lazyload\" title=\"Setting Hover &amp; Focus States in Theme JSON and Global Styles!\" width=\"800\" height=\"450\" data-src=\"https:\/\/www.youtube.com\/embed\/XikXzLLojhk?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<h4>Styling elements at block level<\/h4>\n<p>To understand how we can use and customize styling at block level, let&#8217;s change the lime green background color of the Search block button from the previous section.<\/p>\n<p>In the following code snippets of the <code>core\/search<\/code> block button, I have modified its global default state background color from lime green to red\u00a0 (hex: <code>#FF0000<\/code>) and its <code>:hover<\/code> state to lime green (primary) color.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">&quot;core\/search&quot;: {\n\t&quot;elements&quot;: {\n\t\t&quot;button&quot;: {\n\t\t\t&quot;spacing&quot;: {\n\t\t\t\t&quot;margin&quot;: {\n\t\t\t\t\t&quot;left&quot;: &quot;0px&quot;\n\t\t\t\t},\n\t\t\t\t&quot;padding&quot;: {\n\t\t\t\t\t&quot;bottom&quot;: &quot;var(--wp--preset--spacing--10)&quot;,\n\t\t\t\t\t&quot;top&quot;: &quot;var(--wp--preset--spacing--10)&quot;\n\t\t\t\t}\n\t\t\t},\n\t\t\t&quot;color&quot;: {\n\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--quaternary)&quot;,\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t},\n\t\t\t&quot;:hover&quot;: {\n\t\t\t\t&quot;color&quot;: {\n\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--primary)&quot;,\n\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n\t\t\t\t}\n\t\t\t},\n\t\t\t&quot;:focus&quot;: {\n\t\t\t\t&quot;color&quot;: {\n\t\t\t\t\t&quot;background&quot;: &quot;red&quot;,\n\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n},<\/code><\/pre>\n<p>In the screenshot below, the default button inherits its lime green background color from the global elements, where as the Search button gets its red background color from its <code>core\/search<\/code> block elements styling.<\/p>\n<figure id=\"attachment_2769\" aria-describedby=\"caption-attachment-2769\" style=\"width: 677px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-2769 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/button-search.png\" alt=\"\" width=\"677\" height=\"181\" \/><figcaption id=\"caption-attachment-2769\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2769 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/button-search.png\" alt=\"\" width=\"677\" height=\"181\" \/><\/noscript> Screenshot showing modified Search button with red background. (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-global-styles-for-json-elements\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<p>The next screenshot shows the HTML elements of the Search button and its style at the block level at its default and interactive\u00a0 <code>:hover<\/code>\u00a0 state with different background colors.<\/p>\n<figure id=\"attachment_2771\" aria-describedby=\"caption-attachment-2771\" style=\"width: 912px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2771 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/search-button-hrtml.png\" alt=\"\" width=\"912\" height=\"258\" \/><figcaption id=\"caption-attachment-2771\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2771 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/search-button-hrtml.png\" alt=\"\" width=\"912\" height=\"258\" \/><\/noscript> Screenshot showing Search block HTML (left panel) with default state red (quaternary) background color (top, right), and green (primary) background for its <code>:hover<\/code> state (bottom, right). (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/managing-css-styles-in-a-wordpress-block-theme\/#aa-global-styles-for-json-elements\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<p>In the following section, let&#8217;s look at a few example use cases of styling elements at the top-level as well as at the block-level.<strong><br \/>\n<\/strong><\/p>\n<h6>Example 1: Styling headings elements at top-level<\/h6>\n<p>In the upper level slim-down <code>h1-h6<\/code> level heading elements styling of TT3 <code>theme.json<\/code>, the text color of only <code>h3<\/code> heading is set to secondary (hex: <span class=\"pl-s\"><code>#345C00<\/code><\/span>). You will find the <a href=\"https:\/\/github.com\/WordPress\/twentytwentythree\/blob\/trunk\/theme.json#L624-L658\" target=\"_blank\" rel=\"noopener\">original code here<\/a>.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">...\n...\n {\n  &quot;styles&quot;: {\n   &quot;elements&quot; {\n       &quot;h1&quot;: {\n          &quot;typography&quot;: { }\n        },\n        { ...},\n        &quot;h3&quot;: {\n          &quot;typography&quot;: {  },\n          &quot;color&quot;: {\n            &quot;text&quot;: &quot;var(--wp--preset--color--secondary)&quot;\n          }\n        },\n        {...},\n        &quot;heading&quot;: {\n          &quot;typography&quot;: { },\n\t    &quot;color&quot;: {\n\t      &quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n\t    }\n        }\n    }\n  }\n }\n...\n...<\/code><\/pre>\n<p>The screenshot capture below shows that all the heading levels, with the exception of h3, inherit the default text color, while the h3 header receives the secondary text color.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-2790 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-headings-1.png\" alt=\"\" width=\"964\" height=\"270\" \/><noscript><img decoding=\"async\" class=\"size-full wp-image-2790 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-headings-1.png\" alt=\"\" width=\"964\" height=\"270\" \/><\/noscript><\/p>\n<p>The secondary color of the h3 text will be applied to all the h3 level elements across the website.<\/p>\n<h6>Example 2: Styling comments form<\/h6>\n<p>Now, let&#8217;s say, if we want to target headings in one specific block, then the heading elements should be appended at the block level. For demonstration purposes, I am targeting the <code>post-comment-form<\/code> heading and style with the red color as shown below.<\/p>\n<figure id=\"attachment_2791\" aria-describedby=\"caption-attachment-2791\" style=\"width: 1080px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2791 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/comments-form-2.png\" alt=\"\" width=\"1080\" height=\"450\" \/><figcaption id=\"caption-attachment-2791\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2791 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/comments-form-2.png\" alt=\"\" width=\"1080\" height=\"450\" \/><\/noscript> Screenshot showing post-comments-form reply title with dark green color (left) and with red color (right) styled h3 heading inside the block.<\/figcaption><\/figure>\n<p>In the following example of <code>core\/post-comments-form<\/code> , the color of the h3 heading text is styled red (quaternary, see below) by adding h3 elements inside the <code>post-comment-form<\/code> block.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">...\n...\n&quot;core\/post-comments-form&quot;: {\n        &quot;elements&quot;: {\n            &quot;button&quot;: {\n                 &quot;typography&quot;: {\n                     &quot;fontSize&quot;: &quot;var(--wp--preset--font-size--medium)&quot;\n                 },\n                 &quot;color&quot;: {\n\t\t\t       &quot;background&quot;: &quot;var(--wp--preset--color--quaternary)&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--primary)&quot;,\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n\t\t\t}\n\t\t},\n             &quot;h3&quot;: {\n                 &quot;color&quot;: {\n                      &quot;text&quot;: &quot;var(--wp--preset--color--quaternary)&quot;\n                }\n            }\n        }\n},\n...\n...<\/code><\/pre>\n<p>The next screenshot shows that the red color is applied to <code>.wp-block-post-comments-form h3<\/code> only and not other h3 headings, as they are not part of the <code>post-comment-form<\/code> block.<\/p>\n<figure id=\"attachment_2789\" aria-describedby=\"caption-attachment-2789\" style=\"width: 852px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2789 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-comment-form.png\" alt=\"\" width=\"852\" height=\"278\" \/><figcaption id=\"caption-attachment-2789\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2789 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-comment-form.png\" alt=\"\" width=\"852\" height=\"278\" \/><\/noscript> Screenshot showing comment form HTML and its h3 element styling.<\/figcaption><\/figure>\n<div><\/div>\n<div>In the same way, we can target all blocks by adding elements and applying all block level properties to customize the style at the block level.<\/div>\n<div>\n<h6>Example 3: Styling buttons and file button elements<\/h6>\n<\/div>\n<div>In a emptytheme, the following <code>theme.json<\/code> snippets were added.<\/div>\n<div>\n<pre class=\"line-numbers\"><code class=\"language-json\">{\n\t&quot;version&quot;: 2,\n\t&quot;settings&quot;: {\n\t\t&quot;appearanceTools&quot;: true,\n    &quot;color&quot;: { },\n\t\t&quot;custom&quot;: {\n\t\t&quot;shadow&quot;: &quot;5px 5px 0px -2px var(--wp--preset--color--base), 5px 5px var(--wp--preset--color--contrast)&quot;\n\t\t\t},\n\t\t&quot;layout&quot;: {\n\t\t\t&quot;contentSize&quot;: &quot;700px&quot;,\n\t\t\t&quot;wideSize&quot;: &quot;1000px&quot;\n\t\t},\n    &quot;typography&quot;: {}\n\t},\n  \n     &quot;styles&quot;: {\n\t\t&quot;blocks&quot;: {\n\t\t\t&quot;core\/file&quot;: {\n\t\t\t\t&quot;elements&quot;: {\n\t\t\t\t\t&quot;button&quot;: {\n\t\t\t\t\t\t&quot;border&quot;: {\n\t\t\t\t\t\t\t&quot;radius&quot;: &quot;0&quot;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t&quot;typography&quot;: {\n\t\t\t\t\t\t\t&quot;fontSize&quot;: &quot;var(--wp--preset--font-size--medium)&quot;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\t&quot;color&quot;: {\n\t\t\t\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--secondary)&quot;,\n\t\t\t\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t\t\t\t},\n\t\t\t\t\t\t&quot;:hover&quot;: {\n\t\t\t\t\t\t\t&quot;color&quot;: {\n\t\t\t\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--contrast)&quot;,\n\t\t\t\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--primary)&quot;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t  }\n\t\t\t\t}\n\t\t\t}\n\t   },\n  \t\t&quot;elements&quot;: {\n  \t\t\t&quot;button&quot;: {\n  \t\t\t\t&quot;border&quot;: {\n  \t\t\t\t\t&quot;radius&quot;: &quot;0&quot;\n  \t\t\t\t},\n  \t\t\t\t&quot;color&quot;: {\n  \t\t\t\t\t&quot;background&quot;: &quot;red&quot;,\n  \t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n  \t\t\t\t},\n  \t\t\t\t&quot;outline&quot;: {\n  \t\t\t\t\t&quot;offset&quot;: &quot;3px&quot;,\n  \t\t\t\t\t&quot;width&quot;: &quot;3px&quot;,\n  \t\t\t\t\t&quot;style&quot;: &quot;dashed&quot;,\n  \t\t\t\t\t&quot;color&quot;: &quot;red&quot;\n  \t\t\t\t},\n  \t\t\t\t&quot;typography&quot;: {\n  \t\t\t\t\t&quot;fontSize&quot;: &quot;var(--wp--preset--font-size--medium)&quot;\n  \t\t\t\t},\n  \t\t\t\t&quot;shadow&quot;: &quot;5px 5px 5px 0px rgba(9, 30, 66, 0.25), 5px 5px 5px 1px rgba(9, 30, 66, 0.08)&quot;,\n  \t\t\t\t&quot;:hover&quot;: {\n  \t\t\t\t\t&quot;color&quot;: {\n  \t\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--contrast)&quot;,\n  \t\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n  \t\t\t\t\t},\n  \t\t\t\t\t&quot;outline&quot;: {\n  \t\t\t\t\t\t&quot;offset&quot;: &quot;3px&quot;,\n  \t\t\t\t\t\t&quot;width&quot;: &quot;3px&quot;,\n  \t\t\t\t\t\t&quot;style&quot;: &quot;solid&quot;,\n  \t\t\t\t\t\t&quot;color&quot;: &quot;blue&quot;\n  \t\t\t\t\t}\n  \t\t\t\t},\n  \t\t\t\t&quot;:focus&quot;: {\n  \t\t\t\t\t&quot;color&quot;: {\n  \t\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--contrast)&quot;,\n  \t\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n  \t\t\t\t\t}\n  \t\t\t\t},\n  \t\t\t\t&quot;:active&quot;: {\n  \t\t\t\t\t&quot;color&quot;: {\n  \t\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--secondary)&quot;,\n  \t\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n  \t\t\t\t\t}\n  \t\t\t\t}\n  \t\t\t}\n  \t\t}\n   }\n}<\/code><\/pre>\n<p>Now, let&#8217;s look at the frontend, we should the the buttons and file button styles as shown below.<\/p>\n<div class=\"mceTemp\"><\/div>\n<figure id=\"attachment_4911\" aria-describedby=\"caption-attachment-4911\" style=\"width: 1000px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"wp-image-4911 size-full lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/12\/buttons-blocks.png\" alt=\"\" width=\"1000\" height=\"350\" \/><figcaption id=\"caption-attachment-4911\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"wp-image-4911 size-full lazyload\" src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/12\/buttons-blocks.png\" alt=\"\" width=\"1000\" height=\"350\" srcset=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/12\/buttons-blocks.png 1000w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/12\/buttons-blocks-300x105.png 300w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/12\/buttons-blocks-768x269.png 768w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/12\/buttons-blocks-200x70.png 200w\" sizes=\"(max-width: 1000px) 100vw, 1000px\" \/><\/noscript> Screenshot showing buttons and file buttons styles.<\/figcaption><\/figure>\n<\/div>\n<div><\/div>\n<h6>Example 4: Styling cite elements in blockquotes blocks<\/h6>\n<p>For the quotes block style, I added the following code snippets in my TT3-child theme to target the <em>Cite<\/em> elements within the <code>core\/quote<\/code> block (lines: 14-23).<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">...\n...\n &quot;core\/quote&quot;: {\n\t&quot;border&quot;: {\n\t\t&quot;color&quot;: &quot;var(--wp--preset--color--primary)&quot;,\n\t\t&quot;style&quot;: &quot;solid&quot;,\n\t\t&quot;width&quot;: &quot;0 0 0 2px&quot;\n\t},\n\t&quot;spacing&quot;: {\n\t\t&quot;padding&quot;: {\n\t\t\t&quot;left&quot;: &quot;var(--wp--preset--spacing--50)&quot;\n\t\t}\n\t},\n\t&quot;elements&quot;: {\n\t\t&quot;cite&quot;: {\n\t\t\t&quot;typography&quot;: {\n\t\t\t\t&quot;fontSize&quot;: &quot;var(--wp--preset--font-size--small)&quot;\n\t\t\t},\n\t\t\t&quot;color&quot;: {\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--quaternary)&quot;\n\t\t\t}\n\t\t}\n\t}\n },\n...\n...<\/code><\/pre>\n<p>The following is the frontend appearance of the citation in quote block in a browser.<\/p>\n<figure id=\"attachment_2783\" aria-describedby=\"caption-attachment-2783\" style=\"width: 800px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2783 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-quote-1.png\" alt=\"\" width=\"800\" height=\"158\" \/><figcaption id=\"caption-attachment-2783\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2783 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-quote-1.png\" alt=\"\" width=\"800\" height=\"158\" \/><\/noscript> Screenshot showing text of Cite elements in a quote block in red color.<\/figcaption><\/figure>\n<p>The quote cite elements applies styles with the <code>.wp-block-pullquote.cite<\/code> class as shown below.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-2797 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/pullquote-cite.png\" alt=\"\" width=\"714\" height=\"117\" \/><noscript><img decoding=\"async\" class=\"size-full wp-image-2797 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/pullquote-cite.png\" alt=\"\" width=\"714\" height=\"117\" \/><\/noscript><\/p>\n<p>Similarly, we can also style the cite elements in the <code>core\/pullquote<\/code> block differently from the quote block above, by adding the following code snippets.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\"> &quot;core\/pullquote&quot;: {\n\t&quot;border&quot;: {\n\t\t&quot;width&quot;: &quot;3px 0&quot;,\n\t\t&quot;style&quot;: &quot;solid&quot;,\n\t\t&quot;color&quot;: &quot;var( --wp--preset--color--quaternary)&quot;\n\t},\n\t&quot;spacing&quot;: {\n\t\t&quot;padding&quot;: &quot;var( --wp--preset--spacing--30 ) 0&quot;\n\t},\n\t&quot;typography&quot;: {\n\t\t&quot;fontFamily&quot;: &quot;var( --wp--preset--font-family--inter )&quot;,\n\t\t&quot;fontSize&quot;: &quot;var( --wp--preset--font-size--large )&quot;,\n\t\t&quot;lineHeight&quot;: &quot;var( --wp--custom--line-height--2-xl )&quot;\n\t},\n\t&quot;elements&quot;: {\n\t\t&quot;cite&quot;: {\n\t\t\t&quot;typography&quot;: {\n\t\t\t\t&quot;textTransform&quot;: &quot;uppercase&quot;,\n\t\t\t\t&quot;fontSize&quot;: &quot;var(--wp--preset--font-size--small)&quot;\n\t\t\t},\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}\n\t}\n },\n...\n...<\/code><\/pre>\n<div>When it is seen in a browser, we should see its front appearance as shown in the next screenshot with red borders (lines: 2-6), and the cite text in dark green (secondary) color (lines: 21-23).<\/div>\n<p><img decoding=\"async\" class=\"wp-image-2781 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-pullquote.png\" alt=\"\" width=\"735\" height=\"450\" \/><noscript><img decoding=\"async\" class=\"wp-image-2781 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-pullquote.png\" alt=\"\" width=\"735\" height=\"450\" \/><\/noscript><\/p>\n<p>If we click on the browser inspection tab, the cite elements is also using the same <code>.wp-block-pullquote cite<\/code> class for styling.<\/p>\n<h6>Example 5: Styling caption elements<\/h6>\n<p>For styling figure caption elements, we should add the following code snippets by selecting the top level elements.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">...\n...\n &quot;caption&quot;: {\n\t&quot;typography&quot;: {\n\t\t&quot;fontFamily&quot;: &quot;var( --wp--preset--font-family--system-font )&quot;,\n\t\t&quot;fontSize&quot;: &quot;var( --wp--preset--font-size--small )&quot;,\n\t\t&quot;fontStyle&quot;: &quot;italic&quot;,\n\t\t&quot;lineHeight&quot;: &quot;1.5&quot;\n\t},\n\t&quot;color&quot;: {\n\t\t&quot;text&quot;: &quot;var(--wp--preset--color--quarternary)&quot;\n\t}\n },\n...\n...<\/code><\/pre>\n<p>When I added the above codes in my TT3-Child theme, frontend view of figure caption of one of the text image is seen with red text color (see below).<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-2785 alignnone lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-caption.png\" alt=\"\" width=\"609\" height=\"356\" \/><noscript><img decoding=\"async\" class=\"size-full wp-image-2785 alignnone lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/scrn-caption.png\" alt=\"\" width=\"609\" height=\"356\" \/><\/noscript><\/p>\n<p>The caption elements generates <code>.wp-block-image figcaption<\/code> class for frontend CSS styling. You may also find its application case in this <a href=\"https:\/\/github.com\/wpengine\/frost\/blob\/trunk\/theme.json#L530-L543\" target=\"_blank\" rel=\"noopener\">WP Engine frost<\/a> theme.<\/p>\n<h6>Example 6: Zazzing up buttons styling<\/h6>\n<p>In the preceding section, we made some basic styling of button elements. If you like to reinvigorate the default or interactive states of your buttons, you can add outlines or box-shadows in the <code>theme.json<\/code> file.<\/p>\n<p>For this example, I am following the test instructions of this <a href=\"https:\/\/github.com\/WordPress\/gutenberg\/pull\/43526#issue-1348078288\" target=\"_blank\" rel=\"noopener\">this GitHub ticket<\/a> on a TT3 child theme.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">&quot;elements&quot;: {\n\t&quot;button&quot;: {\n\t\t&quot;outline&quot;: {\n\t\t\t&quot;offset&quot;: &quot;3px&quot;,\n\t\t\t&quot;width&quot;: &quot;3px&quot;,\n\t\t\t&quot;style&quot;: &quot;dashed&quot;,\n\t\t\t&quot;color&quot;: &quot;red&quot;\n\t\t},\n\t\t&quot;:hover&quot;: {\n\t\t\t&quot;outline&quot;: {\n\t\t\t\t&quot;offset&quot;: &quot;3px&quot;,\n\t\t\t\t&quot;width&quot;: &quot;3px&quot;,\n\t\t\t\t&quot;style&quot;: &quot;solid&quot;,\n\t\t\t\t&quot;color&quot;: &quot;blue&quot;\n\t\t\t}\n\t\t}\n\t}\n}<\/code><\/pre>\n<p>When viewing in a browser, you should see your button elements with <em>red<\/em> dashed outline (left). When at <code>:hover<\/code> state, it turns into a solid <em>blu<\/em>e line (right).<\/p>\n<figure id=\"attachment_2792\" aria-describedby=\"caption-attachment-2792\" style=\"width: 1012px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-2792 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/buttons-outlines.png\" alt=\"\" width=\"1012\" height=\"198\" \/><figcaption id=\"caption-attachment-2792\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-2792 lazyload\" src=\"https:\/\/tinjurewp.com\/my-drafts\/wp-content\/uploads\/2022\/10\/buttons-outlines.png\" alt=\"\" width=\"1012\" height=\"198\" \/><\/noscript> Screenshots showing button outlines in default state (left) and <code>:hover<\/code> state (right). (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/adding-box-shadows-to-wordpress-blocks-and-elements\/\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<h6>Adding box-shadow effect in button elements<\/h6>\n<p>In WordPress 6.1, we can add the <a href=\"https:\/\/make.wordpress.org\/core\/tag\/gutenberg-new\/#improving-theme-developer-experience\" target=\"_blank\" rel=\"noopener\">box-show effect<\/a> to the button using <code>theme.json<\/code> elements. Inspired by the example use case in <a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/pixl\/theme.json#L476-L520\" target=\"_blank\" rel=\"noopener\">Pixl theme<\/a>, I modified the button elements in my TT3-Child theme&#8217;s <code>theme.json<\/code> file as follows.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">&quot;elements&quot;: {\n\t\t&quot;button&quot;: {\n\t\t\t&quot;border&quot;: {\n\t\t\t\t&quot;radius&quot;: &quot;0&quot;\n\t\t\t},\n\t\t\t&quot;color&quot;: {\n\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--tertiary)&quot;,\n\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--contrast)&quot;\n\t\t\t},\n\t\t\t&quot;outline&quot;: {\n\t\t\t\t&quot;offset&quot;: &quot;3px&quot;,\n\t\t\t\t&quot;width&quot;: &quot;3px&quot;,\n\t\t\t\t&quot;style&quot;: &quot;dashed&quot;,\n\t\t\t\t&quot;color&quot;: &quot;red&quot;\n\t\t\t},\n\t\t\t&quot;typography&quot;: {\n\t\t\t\t&quot;fontSize&quot;: &quot;var(--wp--preset--font-size--medium)&quot;\n\t\t\t},\n\t\t\t&quot;shadow&quot;: &quot;5px 5px 5px 0px rgba(9, 30, 66, 0.25), 5px 5px 5px 1px rgba(9, 30, 66, 0.08)&quot;,\n\t\t\t&quot;:hover&quot;: {\n\t\t\t\t&quot;color&quot;: {\n\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--contrast)&quot;,\n\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t\t},\n\t\t\t\t&quot;outline&quot;: {\n\t\t\t\t\t&quot;offset&quot;: &quot;3px&quot;,\n\t\t\t\t\t&quot;width&quot;: &quot;3px&quot;,\n\t\t\t\t\t&quot;style&quot;: &quot;solid&quot;,\n\t\t\t\t\t&quot;color&quot;: &quot;blue&quot;\n\t\t\t\t}\n\t\t\t},\n\t\t\t&quot;:focus&quot;: {\n\t\t\t\t&quot;color&quot;: {\n\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--contrast)&quot;,\n\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t\t}\n\t\t\t},\n\t\t\t&quot;:active&quot;: {\n\t\t\t\t&quot;color&quot;: {\n\t\t\t\t\t&quot;background&quot;: &quot;var(--wp--preset--color--secondary)&quot;,\n\t\t\t\t\t&quot;text&quot;: &quot;var(--wp--preset--color--base)&quot;\n\t\t\t\t}\n\t\t\t}\n\t\t}<\/code><\/pre>\n<p>Screenshot of the above box shadow (line 13) looks in a browser as shown below:<\/p>\n<figure id=\"attachment_4839\" aria-describedby=\"caption-attachment-4839\" style=\"width: 900px\" class=\"wp-caption alignnone\"><img decoding=\"async\" class=\"size-full wp-image-4839 lazyload\" src=\"data:image\/gif;base64,R0lGODlhAQABAIAAAAAAAP\/\/\/yH5BAEAAAAALAAAAAABAAEAAAIBRAA7\" data-src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/09\/button-shadows.png\" alt=\"\" width=\"900\" height=\"207\" \/><figcaption id=\"caption-attachment-4839\" class=\"wp-caption-text\"><noscript><img decoding=\"async\" class=\"size-full wp-image-4839 lazyload\" src=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/09\/button-shadows.png\" alt=\"\" width=\"900\" height=\"207\" srcset=\"https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/09\/button-shadows.png 900w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/09\/button-shadows-300x69.png 300w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/09\/button-shadows-768x177.png 768w, https:\/\/learncode.tinjurewp.com\/wp-content\/uploads\/2022\/09\/button-shadows-200x46.png 200w\" sizes=\"(max-width: 900px) 100vw, 900px\" \/><\/noscript> Screenshot showing button with box-shadow effect. (Screenshot credit: <a href=\"https:\/\/css-tricks.com\/adding-box-shadows-to-wordpress-blocks-and-elements\/\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a>)<\/figcaption><\/figure>\n<p>For little smoother box-shadow (above right), the next shadow effect can be used.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-json\">{\n  ...\n  &quot;styles&quot;: {\n    &quot;elements&quot;: {\n      &quot;button&quot;: {\n         &quot;shadow&quot;: &quot;5px 5px 5px 0px rgba(9, 30, 66, 0.25), 5px 5px 5px 1px rgba(9, 30, 66, 0.08)&quot;\n      }\n    }\n  }\n}<\/code><\/pre>\n<p>You may find more detailed in-depth discussions about the box-shadow feature in this <a href=\"https:\/\/github.com\/WordPress\/gutenberg\/pull\/41972\" target=\"_blank\" rel=\"noopener\">GitHub PR ticket.<\/a> To learn more about the style JSON elements, you can check out the following block themes.<\/p>\n<p><em>Buttons elements<\/em><\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/pixl\/theme.json#L477-L520\" target=\"_blank\" rel=\"noopener\">Pixl<\/a>\u00a0theme button elements used for border, color, typography, shadow, hover, and activate state.<\/li>\n<li><a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/vivre\/theme.json#L564-L582\" target=\"_blank\" rel=\"noopener\">Vivre<\/a>\u00a0theme &#8211; color, border, typography<\/li>\n<li><a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/block-canvas\/theme.json#L264-L286\" target=\"_blank\" rel=\"noopener\">Block-canvas<\/a>\u00a0theme with color, text, typography<\/li>\n<li><a href=\"https:\/\/github.com\/WordPress\/twentytwentythree\/blob\/trunk\/theme.json#L567-L593\" target=\"_blank\" rel=\"noopener\">TT3<\/a>\u00a0theme color, hover, focus, active<\/li>\n<li><a href=\"https:\/\/github.com\/wpengine\/frost\/blob\/trunk\/theme.json#L453-LL476\" target=\"_blank\" rel=\"noopener\">Frost<\/a> theme with border, color, spacing, typography<\/li>\n<li><a href=\"https:\/\/themes.trac.wordpress.org\/browser\/disco\/1.0.1\/theme.json#L517-L543\" target=\"_blank\" rel=\"noopener\">Disco<\/a> theme with border, color, typography<\/li>\n<\/ul>\n<div><em>Cite elements<\/em><\/div>\n<ul>\n<li>\u00a0<a href=\"https:\/\/github.com\/Automattic\/themes\/tree\/trunk\/loudness\">Laudness<\/a>\u00a0(example\u00a0<a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/loudness\/theme.json#L258-L285\">link<\/a>\u00a0)<\/li>\n<\/ul>\n<div><em>Comments form elements<\/em><\/div>\n<ul>\n<li>\u00a0<a href=\"https:\/\/github.com\/Automattic\/themes\/tree\/trunk\/pixl\">Pixl<\/a> (example\u00a0<a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/pixl\/theme.json#L300-L318\">link<\/a> )<\/li>\n<li>Rainfall (example\u00a0<a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/rainfall\/theme.json#L277-L303\">link<\/a>\u00a0),<\/li>\n<li>Block canvas (example <a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/block-canvas\/theme.json#L122-L147\">link<\/a>\u00a0)<\/li>\n<\/ul>\n<div><em>Forms elements<\/em><\/div>\n<ul>\n<li>Blockbase (example <a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/blockbase\/theme.json#L163-L217\">link<\/a>\u00a0)<\/li>\n<\/ul>\n<div><em>Search button elements<\/em><\/div>\n<ul>\n<li>Rain fall (example <a href=\"https:\/\/github.com\/Automattic\/themes\/blob\/trunk\/rainfall\/theme.json#L304-L330\">link<\/a>)<\/li>\n<\/ul>\n<h6>Wrapping up<\/h6>\n<p>In this section, we look at the examples of styling elements at both global and block level, with some use case examples.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Notes: This post is part 2 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. In the previous section, we briefly overview the JASON elements and discussed how they are used in a theme.json file. In this section, let&#8217;s expand JSON [&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-4857","post","type-post","status-publish","format-standard","hentry","category-full-site-editing"],"_links":{"self":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/4857","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=4857"}],"version-history":[{"count":0,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/4857\/revisions"}],"wp:attachment":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/media?parent=4857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/categories?post=4857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/tags?post=4857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}