Title: Block theme styles
Published: 24 May 2024
Last modified: 31 July 2024

---

[Home](https://learn.wordpress.org)[Courses](https://learn.wordpress.org/courses/)
[Intermediate Theme Developer](https://learn.wordpress.org/course/intermediate-theme-developer/)
Block theme styles

 [ Exit Course ](https://learn.wordpress.org/course/intermediate-theme-developer/)

 1.   a.  [   Global theme settings  ](https://learn.wordpress.org/lesson/global-theme-settings/)
         [Preview](https://learn.wordpress.org/lesson/global-theme-settings/)
      b.  [   Block theme styles  ](https://learn.wordpress.org/lesson/block-theme-styles/)
         [Preview](https://learn.wordpress.org/lesson/block-theme-styles/)
      c.  [   Templates  ](https://learn.wordpress.org/lesson/custom-templates/) [Preview](https://learn.wordpress.org/lesson/custom-templates/)
      d.  [   Theme Patterns  ](https://learn.wordpress.org/lesson/theme-patterns/) [Preview](https://learn.wordpress.org/lesson/theme-patterns/)
      e.  [   Style Variations  ](https://learn.wordpress.org/lesson/style-variations/)
         [Preview](https://learn.wordpress.org/lesson/style-variations/)
 2.   5 lessons
 3.   a.  [   Template overview  ](https://learn.wordpress.org/lesson/template-overview/)
         [Preview](https://learn.wordpress.org/lesson/template-overview/)
      b.  [   Template Hierarchy  ](https://learn.wordpress.org/lesson/template-hierarchy/)
         [Preview](https://learn.wordpress.org/lesson/template-hierarchy/)
      c.  [   Template parts  ](https://learn.wordpress.org/lesson/template-parts-4/) 
         [Preview](https://learn.wordpress.org/lesson/template-parts-4/)
 4.   3 lessons
 5.   a.  [   Custom functionality  ](https://learn.wordpress.org/lesson/custom-functionality/)
         [Preview](https://learn.wordpress.org/lesson/custom-functionality/)
      b.  [   Including assets  ](https://learn.wordpress.org/lesson/including-assets/)
         [Preview](https://learn.wordpress.org/lesson/including-assets/)
      c.  [   Block stylesheets  ](https://learn.wordpress.org/lesson/block-stylesheets/)
         [Preview](https://learn.wordpress.org/lesson/block-stylesheets/)
      d.  [   Block style variations  ](https://learn.wordpress.org/lesson/block-style-variations/)
         [Preview](https://learn.wordpress.org/lesson/block-style-variations/)
      e.  [   Block variations  ](https://learn.wordpress.org/lesson/block-variations/)
         [Preview](https://learn.wordpress.org/lesson/block-variations/)
 6.   5 lessons
 7.   a.  [   Introduction to Classic themes  ](https://learn.wordpress.org/lesson/introduction-to-classic-themes/)
         [Preview](https://learn.wordpress.org/lesson/introduction-to-classic-themes/)
      b.  [   The Loop  ](https://learn.wordpress.org/lesson/the-loop/) [Preview](https://learn.wordpress.org/lesson/the-loop/)
      c.  [   Theme options  ](https://learn.wordpress.org/lesson/theme-options/) [Preview](https://learn.wordpress.org/lesson/theme-options/)
      d.  [   theme.json in Classic themes  ](https://learn.wordpress.org/lesson/theme-json-in-classic-themes/)
         [Preview](https://learn.wordpress.org/lesson/theme-json-in-classic-themes/)
      e.  [   Converting a Classic theme to a Block theme  ](https://learn.wordpress.org/lesson/converting-a-classic-theme-to-a-block-theme/)
         [Preview](https://learn.wordpress.org/lesson/converting-a-classic-theme-to-a-block-theme/)
 8.   5 lessons
 9.   a.  [   Best practices for developing an accessible theme  ](https://learn.wordpress.org/lesson/best-practices-for-developing-an-accessible-theme/)
         [Preview](https://learn.wordpress.org/lesson/best-practices-for-developing-an-accessible-theme/)
      b.  [   Tools for testing theme accessibility  ](https://learn.wordpress.org/lesson/tools-for-testing-theme-accessibility/)
         [Preview](https://learn.wordpress.org/lesson/tools-for-testing-theme-accessibility/)
 10.  2 lessons
 11.  a.  [   Themes and user privacy  ](https://learn.wordpress.org/lesson/themes-and-user-privacy/)
         [Preview](https://learn.wordpress.org/lesson/themes-and-user-privacy/)
 12.  1 lesson
 13.  a.  [   Child themes  ](https://learn.wordpress.org/lesson/child-themes/) [Preview](https://learn.wordpress.org/lesson/child-themes/)
      b.  [   UI Best Practices  ](https://learn.wordpress.org/lesson/ui-best-practices/)
         [Preview](https://learn.wordpress.org/lesson/ui-best-practices/)
      c.  [   JavaScript in Themes  ](https://learn.wordpress.org/lesson/javascript-in-themes/)
         [Preview](https://learn.wordpress.org/lesson/javascript-in-themes/)
      d.  [   Build Process  ](https://learn.wordpress.org/lesson/build-process/) [Preview](https://learn.wordpress.org/lesson/build-process/)
      e.  [   Plugin API hooks  ](https://learn.wordpress.org/lesson/plugin-api-hooks/)
         [Preview](https://learn.wordpress.org/lesson/plugin-api-hooks/)
      f.  [   Testing your theme  ](https://learn.wordpress.org/lesson/testing-your-theme/)
         [Preview](https://learn.wordpress.org/lesson/testing-your-theme/)
 14.  6 lessons
 15.  a.  [   The WordPress.org Theme Directory  ](https://learn.wordpress.org/lesson/the-wordpress-org-theme-directory/)
         [Preview](https://learn.wordpress.org/lesson/the-wordpress-org-theme-directory/)
      b.  [   Required theme files  ](https://learn.wordpress.org/lesson/required-theme-files/)
         [Preview](https://learn.wordpress.org/lesson/required-theme-files/)
      c.  [   Preparing your theme for submission  ](https://learn.wordpress.org/lesson/preparing-your-theme-for-submission/)
         [Preview](https://learn.wordpress.org/lesson/preparing-your-theme-for-submission/)
      d.  [   Submitting your theme to WordPress.org  ](https://learn.wordpress.org/lesson/submitting-your-theme-to-wordpress-org/)
         [Preview](https://learn.wordpress.org/lesson/submitting-your-theme-to-wordpress-org/)
      e.  [   Updating your theme  ](https://learn.wordpress.org/lesson/updating-your-theme/)
         [Preview](https://learn.wordpress.org/lesson/updating-your-theme/)
 16.  5 lessons

### Global Settings and Styles

# Block theme styles

Welcome to this lesson on styles for WordPress themes.

With this lesson, you will:

 * explore the style hierarchy,
 * modify theme styles using the Site Editor and export the changes,
 * understand how WordPress uses the JSON syntax to generate CSS in a browser, and
 * configure presets via the settings property and apply them in the theme.json 
   styles property.

## The WordPress style hierarchy

At the bottom, we have root elements, such as body text. The next level is individual
elements, such as headings, for example, the H1 tag. And finally at the top, we 
have blocks, such as a button block. So anything that would be applied to the block
level would take precedence over all of the other styling within your theme.

## Modify theme styles

Let’s modify theme styles using the site editor and export the changes. The Create
Block theme plugin is an invaluable tool for any theme developer. Do check out the
introductory lesson within the Beginner’s Learning Pathway for developers.

One of the best features I’ve discovered using the Create Block theme plugin is 
the ability to save changes directly to my theme file. If I were to now make a change
within global styles, such as adding a new color, for example, to the custom palette,
so I can search for a color or I could enter the hex code and then I can name my
color. I’ll name this one purple and then you would hit done. And then if I were
to hit save, this change is saved to the database. We see the Create Block theme
plugin sidebar and the save changes option. This removes the changes from the database
and pushes them to the theme files.

And now let’s open the theme.json file so we can search for the new purple color.
And you can see it there within settings as a new color available for the end user
to use.

## How WordPress uses the JSON syntax to generate CSS in a browser

We’ll take a look at the default Twenty Twenty-Four theme. This is a block theme
and if we were to inspect the code and take a look at, say for example, the H1 tag,
so we’ll inspect it here on the left and on the right we see the generated CSS.

WordPress takes the settings, color, contrast, and then applies it to the H1 heading
here. We’re going to take a look at how this is done now in theme.json. So here 
you see how within settings we have the palette and the contrast color. And then
if we were to scroll down to the styles property, we would see how the contrast 
color is being applied to text.

## How presets are written within theme.json

Let’s configure presets using theme.json with another example now. Here we have 
a getting started theme and we want to start customizing it by adding our palette.
Go into settings and set the default palette from WordPress to false and then add
the property palette and start adding our colors. And note here that we’re using
a generic naming convention as opposed to naming the color.

For instance here this is a dark green and instead of using green for the name and
slug we just use contrast. This makes it much easier to do color changes going forward
and then we see it being applied at the bottom here under styles.

Now, let’s take a closer look at an example from the Twenty Twenty-Four theme. We
have the settings property with the color, name and slug. And then for styles to
apply it we would use the format here with the feature being color and then the 
slug for example is accent-3.

WordPress generates the CSS by creating the class has-slug-feature. We can see this
in action by applying the color to the text here and then if we inspect that paragraph
we’ll see how WordPress takes up preset and creates the class has-accent-3-color.

## Next steps

As always you can refer to the [theme handbook available to you on WordPress.org](https://developer.wordpress.org/themes/)
and you can also take a look at the [styles reference guide](https://developer.wordpress.org/themes/global-settings-and-styles/styles/styles-reference/)
in order to find all of the available style properties that you can add to your 
theme.json file.

 This is a preview lesson

Register or sign in to take this lesson.

 [ Take course ](https://learn.wordpress.org/course/intermediate-theme-developer/)

 [ Sign in ](https://login.wordpress.org/?redirect_to=https%3A%2F%2Flearn.wordpress.org%2Flesson%2Fblock-theme-styles%2F&locale=en_US)

##  Suggestions

 Found a typo, grammar error or outdated screenshot? [Contact us](https://learn.wordpress.org/report-content-feedback/).