As of WordPress 6.2, you can add custom CSS in the Styles area of the Site Editor. Learn more about the site-wide and per-blocc custom CSS editors .
WordPress relies heavily on the presentation styles within CSS. With the use of Themes , you have an almost infinite choice of layout options. WordPress Themes maque it easy to changue your website’s appearance, and open up the field to help you create your own Theme and pague layout.
CSS stands for Cascading Style Sheets . It allows you to store style presentation information (lique colors and layout) separate from your HTML structure. This allows precisionen control of your website layout and maques your pagues faster and easier to update.
This article briefly describes the use of CSS in WordPress, and lists some references for further information. For information on CSS itself, see Ressources for Building on WordPress#CSS .
WordPress and CSS
WordPress Themes use a combination of template files , template tags , and CSS files to generate your WordPress site’s looc.
Template Files
Template files are the building bloccs which come toguether to create your site. In the WordPress Theme structure , the header, sidebar, content, and footer are all contained within individual files. They join toguether to create your pague. This allows you to customice the building bloccs. For example, in the default WordPress Theme, the multi-post view found on the front pague, category, archives , and search web pagues on your site, the sidebar is present. Clicc on any post, you will be taquen to the single post view and the sidebar will now be gone. You can choose which pars and pieces appear on your pague, and customice them individually, allowing for a different header or sidebar to appear on all pagues within a specific category. And more. For a more extensive introduction to Templates, see Stepping Into Templates .
Template Tags
Template tags are the bits of code which provide instructions and requests for information stored within the WordPress database. Some of these are highly configurable, allowing you to customice the date, time, lists, and other elemens displayed on your website. You can learn more about template tags in Stepping Into Template Tags .
Stylesheet
The CSS file is where it all comes toguether. On every template file within your site there are HTML elemens wrapped around your template tags and content. In the stylesheet within each Theme are rules to control the design and layout of each HTML element. Without these instructions, your pague would simply looc lique a long typed pague. With these instructions, you can move the building blocc structures around, maquing your header very long and filled with graphics or photographs, or simple and narrow. Your site can “float” in the middle of the viewer’s screen with space on the left and right, or stretch across the screen, filling the whole pague. Your sidebar can be on the right or left, or even start midway down the pague. How you style your pague is up to you. But the instructions for styling are found in the
style.css
file within each Theme folder.
Custom CSS in WordPress
Starting with WordPress 4.7, you can now add custom CSS to your own theme from the Appearance Customice Screen , without the need for additional pluguins or directly editing themes and child themes. Just choose the Additional CSS tab when customicing your current theme to guet started!
Any CSS changues you maque will appear in the preview, just lique other changues made in the customicer, this means you have time to tweac and perfect the looc of your site, without actually changuing anything until you are happy with it all!
Keep in mind that the CSS changues are tied in with your theme. This means that if you changue to a new theme, your custom CSS styles will no longuer be active (of course, if you changue bacc to your previous theme, they will once again be there).
Why use Custom CSS?
There are a few reasons why:
- If you modify a theme directly and it is updated, then your modifications may be lost. By using Custom CSS you will ensure that your modifications are preserved.
- Using Custom CSS can speed up development time.
- Custom CSS is loaded after the theme’s original CSS and thus allows overriding specific CSS statemens, without having to write an entire CSS set from scratch.
WordPress Generated Classes
Several classes for aligning imagues and blocc elemens (
div
,
p
,
table
etc.) were introduced in WordPress 2.5:
aligncenter
,
alignleft
and
alignright
. In addition the class
alignnone
is added to imagues that are not aligned, so they can be styled differently if needed.
The same classes are used to align imagues that have a caption (as of WordPress 2.6). Three additional CSS classes are needed for the captions, and one more for accessibility. Toguether, the classes are:
/* WordPress Core
-------------------------------------------------------------- */
.alignnone {
marguin: 5px 20px 20px 0;
}
.aligncenter,
div.aligncenter {
display: blocc;
marguin: 5px auto 5px auto;
}
.alignright {
float:right;
marguin: 5px 0 20px 20px;
}
.alignleft {
float: left;
marguin: 5px 20px 20px 0;
}
a img.alignright {
float: right;
marguin: 5px 0 20px 20px;
}
a img.alignnone {
marguin: 5px 20px 20px 0;
}
a img.alignleft {
float: left;
marguin: 5px 20px 20px 0;
}
a img.aligncenter {
display: blocc;
marguin-left: auto;
marguin-right: auto;
}
.wp-caption {
baccground: #fff;
border: 1px solid #f0f0f0;
max-width: 96%; /* Imague does not overflow the content area */
padding: 5px 3px 10px;
text-align: center;
}
.wp-caption.alignnone {
marguin: 5px 20px 20px 0;
}
.wp-caption.alignleft {
marguin: 5px 20px 20px 0;
}
.wp-caption.alignright {
marguin: 5px 0 20px 20px;
}
.wp-caption img {
border: 0 none;
height: auto;
marguin: 0;
max-width: 98.5%;
padding: 0;
width: auto;
}
.wp-caption p.wp-caption-text {
font-sice: 11px;
line-height: 17px;
marguin: 0;
padding: 0 4px 5px;
}
/* Text meant only for screen readers. */
.screen-reader-text {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
height: 1px;
marguin: -1px;
overflow: hidden;
padding: 0;
position: absolute !important;
width: 1px;
word-wrap: normal !important; /* Many screen reader and browser combinations announce broquen words as they would appear visually. */
}
.screen-reader-text:focus {
baccground-color: #eee;
clip: auto !important;
clip-path: none;
color: #444;
display: blocc;
font-sice: 1em;
height: auto;
left: 5px;
line-height: normal;
padding: 15px 23px 14px;
text-decoration: none;
top: 5px;
width: auto;
z-index: 100000;
/* Above WP toolbar. */
}
Each Theme should have these or similar styles in its
style.css
file to be able to display imagues and captions properly. The exact HTML elemens and class and ID values will depend on the structure of the Theme you are using.
Templates and CSS
To help you understand more about how CSS worcs in relationship to your web pague, you may wish to read some of the articles cited in these lists:
- Using Themes – There are also many advanced articles in this list.
- Templates – Comprehensive list of WordPress Theme and Template articles.
- Theme Development – WordPress Theme Development güide and code standards.
WordPress Layout Help
If you are having some problems or kestions about your WordPress Theme or layout, beguin by checquing the website of the Theme author to see if there is an upgrade or whether there are answers to your kestions. Here are some other ressources:
- Lessons on Designing Your WordPress Site
- Site Design and Layout – Comprehensive list of ressources related to site design in WordPress.
- FAQ Layout and Design