style.css 是 WordPress 主题的必需文件,主要用于通过文件头部的配置数据注册主题,并常作为前端和编辑器 CSS 的载体。本文档指导开发者如何配置 style.css 文件头以定义主题信息。
/**
* Theme Name: Fabled Sunset
* Theme URI: https://example.com/fabled-sunset
* Description: Custom theme description...
* Version: 1.0.0
* Author: Your Name
* Author URI: https://example.com
* Tags: block-patterns, full-site-editing
* Text Domain: fabled-sunset
* Domain Path: /assets/lang
* Tested up to: 6.4
* Requires at least: 6.2
* Requires PHP: 7.4
* License: GNU General Public License v2.0 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/As described in Theme Structure, WordPress requires that all themes include a style.css file. Its most important function is to “register” the theme with WordPress through configuration data at the top of the file. Many themes also use it to serve CSS to the front-end (and even the editor).
In this document, you will learn how to configure your theme data via the style.css file header.
The style.css file header is used to configure data about the theme. WordPress uses this information to determine how some features work and displays some of this data under the Appearance > Themes screen for users.
Here is a look at what the theme details overlay looks like for the default Twenty Twenty-Three theme:

Most of that information is pulled directly from the style.css file header. It is one of the most vital parts of creating a WordPress theme.
When determining which themes are available to activate, WordPress searches through each folder under /wp-content/themes, looking for a style.css file. If one is found, it pulls the first 8kb of data from the file and determines if there is a file header with standard fields defined.
In themes, this is merely a CSS comment block with some standard keys and values defined.
Suppose you were creating a theme with the folder name of fabled-sunset. WordPress would look for your theme’s style.css in the following location:
wp-content/
themes/
fabled-sunset/
style.cssFor WordPress to recognize your theme, you would at least need the Theme Name field defined at the top of style.css like so:
/**
* Theme Name: Fabled Sunset
*/
This is the minimum required header field for a valid theme. Of course, you’ll want to add much more information about your theme.
There are many supported fields, and you will likely use most of them in your themes. Here is a quick look at a theme’s style.css file header with each of the fields configured:
/**
* Theme Name: Fabled Sunset
* Theme URI: https://example.com/fabled-sunset
* Description: Custom theme description...
* Version: 1.0.0
* Author: Your Name
* Author URI: https://example.com
* Tags: block-patterns, full-site-editing
* Text Domain: fabled-sunset
* Domain Path: /assets/lang
* Tested up to: 6.4
* Requires at least: 6.2
* Requires PHP: 7.4
* License: GNU General Public License v2.0 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
The following list outlines what each of these fields does.
While the Theme Name is the only field required to work with WordPress, you must also include some other fields when submitting a theme to the WordPress theme directory. These fields are marked with * below.
X.X or X.X.X format./languages.X.X format (e.g., 6.4, 6.2.1, etc.).X.X format (e.g., 6.3, 6.2.1, etc.).X.X format (e.g., 8.0, 7.4, etc.).When building a child theme, there is one additional supported field: Template. This is used to designate the parent theme’s folder.
If the fictional “Fabled Sunset” theme listed above was the parent of your child theme named “Grand Sunrise,” your style.css header fields would look similar to this:
/**
* Theme Name: Grand Sunrise
* Template: fabled-sunset
* ...other header fields
*/
The Template field must match the parent theme’s folder name exactly (relative to the wp-content/themes directory) for this to work. Otherwise, WordPress will not be able to appropriately match them.
You can learn more about child themes in the Advanced Topics chapter.
Some third-party marketplaces or systems may also make use of custom header fields. These are not officially supported by WordPress, but they are definitely allowed and should not negatively impact how the theme works within WordPress.
The style.css file is not merely a configuration file. You can also use it to write custom CSS code to alter the design of your theme, assuming the file is properly loaded.
With block themes, most or all of the design is ideally handled through the theme.json file, which you will learn about in the Global Settings and Styles documentation.
But there are times when you will want or need to add custom CSS. You can learn more about this in the Including Assets documentation.