Skip to content

Using CSS

CSS (Cascading Style Sheets) is a sheet containing formatting rules used to style the design and layout of HTML content on a web page. Considering that the interface we work in, Beaver Builder, gives us plenty of styling opportunity using little to no CSS, its our goal to minimize the use of CSS to only when its absolutely necessary. Too much CSS can also contribute to slowing site loading speeds and we should try to avoid it if possible. Learn about the best practices for using CSS vs built in module styling features, how to write it properly and where to put it.

Coding Standards

Create Code that is Meaningful, Consistent & Readable


1. Keep your code organized (CSS Structure)

  • 1

    The use of our CSS template is required

    This top to bottom > sitewide > page specific > module specific > mobile approach keeps things organized, and easier to find for future updates (see accordion below)
    It helps if you think of your CSS as a house. It makes no sense to add a textured wall before adding a roof. Some classes are already added to the template, but you don’t have to use them, unless you feel it’s needed.

  • 2

    Consistent Indentation

    Use tab, not spaces, to indent each property.

  • 3

    Spacing & Clarity

    Add two blank lines between sections and one blank line between blocks in a section.

  • 4

    Readability

    Write each selector on its own line, ending in either a comma or an opening curly brace. Include one space between the selector and the opening brace. Property-value pairs should be on their own line, with one tab of indentation and an ending semicolon. The closing brace should be flush left, using the same level of indentation as the opening selector.

  • 5

    Use dashes in class names

    Don’t use under_scores or “camelCase” to name classes or IDs. 

  • 6

    Write hex values in lowercase

    #fff vs #FFFFFF

  • 7

    Shorthand Properties

    If you have several properties that are alike, group them in an order that makes sense, and use shorthand properties whenever possible.
    Instead of:
    border-width: 1px;
    border-style: solid;
    border-color: black;
    Use:
    border: 1px solid black;

  • 8

    Enclose URLs in single quotes

    url('/image.png') vs url("/image.png")

  • 9

    Don’t use units for zero (0) values

    except for angles (deg) and time (s or ms)
    margin-right: 0; vs margin-right: 0px;

  • 10

    Don’t use IDs and overly-specific selectors to style

    Only use these when absolutely necessary (e.g. form controls or page anchors).

  • 11

    Do not place media queries outside of the designated areas within the template

    but comment the related area as having media queries, as delineated in the suggested template.

  • 12

    Organize the code within the template from top to bottom

    do not dump styles at the end of the CSS, and notate sections/pages appropriately.

(4) DO:
#selector-1, #selector-2, #selector-3 { background: #fff; color: #000; }
(4) DON'T:
/*avoid this if possible*/ #selector-1, #selector-2, #selector-3 { background: #fff; color: #000; } /*never do this*/ #selector-1 { background: #fff; color: #000; }
DO:
/* This is a comment about this selector */ .this-selector { position: absolute; top: 0 !important; /* I should explain why this is so !important */ }

2. Notate appropriately

Comment liberally. If the code doesn’t explain itself, explain it with detailed comments. Examples are uses of z-index or browser-specific hacks/fixes.

  • Don’t "!important" - Prioritize resolving specificity issues before resorting to !important
  • If you absolutely MUST, explain why using comments in your CSS

3. Name your classes and IDs in a meaningful or generic way

Read more about properly naming elements and classes in the "Styling with CSS" section below.
Be careful of creating classes that already exist.

4. Don't write CSS for things you can style in the builder or Customizer

  • Only write CSS for things that cannot be accomplished through Beaver Builder or through the customizer. Things like font styles, width, margins, and padding can all be accomplished without CSS.
  • Before writing CSS, make sure that there are no modules that can achieve the look you are going for, as many times there are at least two variations of the same type of module, due to the fact that our plugin package includes two premium add-ons (Ultimate Add-ons and PowerPack). In the event that the styling/function doesn’t exist on one of them, it probably exists within the other.
  • The vast majority of new websites built with GD Core do not need ANY CSS.
  • When you write code referencing a module (especially if you mark it !important, which you shouldn’t), you are overwriting the module settings. So what happens is that when you go into the actual Beaver Builder to edit that module, the changes you are trying to apply, just won't, because the code is overwriting it. That makes the customer experience very frustrating and also our work when updating, more complicated than it should.

5. Do not target Beaver Builder auto generated classes/IDs

(any class/ID that starts with .fl-)

If you look at Beaver Builder HTML outputs, you see a lot of class names that start with "fl-". Those classes are generated by Beaver Builder theme and plugin. Some of them have names that make sense (like .fl-page-content, for example), but a lot of them will have a sequence of numbers that are not easily identifiable. You should not target those classes in your CSS, but create custom classes instead, and target those. Always keep in mind the guidelines on how to name classes (read more about properly naming elements and classes in the section below), so you don’t run the risk of creating a class that already exist, or that can easily become obsolete throughout the life of the website.

Examples of bad CSS

This is a classic example of bad CSS. Let’s go through it to see why:

  • There’s no line break in between classes
  • Font styles within media queries are entered with !important. Font styles are to be set within the customizer. Within the Beaver Builder modules, you can set specific sizes for mobile. You should never use !important to override these settings, and you should avoid placing media queries outside of the media queries area within our template (This example is not using our template either)
  • .fl classes are being targeted, with !important and no notes on what they are, to do things that are achievable through the modules (width, margin-top, text-align…)
  • Overall is just convoluted code and it uses unidentifiable classes with redundant properties

Source: Beaver Builder KB - Theme CSS Reference

CSS Template

CSS Template For Beaver Builder Sites - MUST USE - Place in Customizer > Additional CSS Tab

/*------------------------------- TYPOGRAPHY --------------------------------*/ body p, .entry-content p, .entry-content ul li, .entry-content ul, .entry-content a, .pp-sub-heading p { } /*-------------------------------- HEADER ---------------------------------*/ /*--- Media queries? Y/N ---*/ /*------------------------------- NAVIGATION --------------------------------*/ /*--- Media queries? Y/N ---*/ /*-------------------------------- BUTTONS ----------------------------------*/ /*--- Media queries? Y/N ---*/ a.button, span.fl-button-text, span.uabb-button-text.uabb-creative-button-text, .gform_button.button, a.fl-button { } /*---------------------------------- FOOTER ---------------------------------*/ /*--- Media queries? Y/N ---*/ /*------------------------------ BB MODULES ---------------------------------*/ /*--- MODULE NAME Description of section Media queries? Y/N ---*/ /*------------------------------ PAGE SPECIFIC ---------------------------------*/ /*--- PAGE NAME Description of section Media queries? Y/N ---*/ /*------------------------------- LARGE SCREENS ONLY ---------------------------------*/ @media screen and (min-width: 769px){ } /*------------------------------- LAPTOP SCREEN - 1366 ---------------------------------*/ @media screen and (max-width: 1366px){ } /*------------------------------- IPAD PRO SCREENS - 1024 ---------------------------------*/ @media screen and (max-width: 1024px){ } /*-------------------------------- TABLET SCREENS AND SMALLER --------------------------------*/ @media screen and (max-width: 768px){ } /*------------------------------- MOBILE SCREENS ONLY ---------------------------------*/ @media screen and (max-width: 480px){ }

Styling With CSS

Follow This Order of Operation

  • 1

    First, Use the Customizer

    Use the customizer to style your headings, body text, buttons, accent colors, and anything you can define for defaults being used across the theme. Reference: Customizer > Style Controls

  • 2

    Next, Style the Module

    Once in Beaver Builder, use modules to style any items that aren't defined in customizer defaults such as module specific styling, font sizes in callouts, background images and row separators for CTA rows dividing page content, etc. Give the modules and rows you're styling classes especially if you're using them in different places across the site or if there are styling items that the module itself doesn't give you an option to modify. Reference: Beaver Builder Practices > Saving Templates Important Rules

  • 3

    Finally, Use CSS

    Use CSS to target the custom classes of those modules that didn't give you the specific modification options you were looking for. Use CSS after the site is built and you need to perhaps change all styled dual Heading H3 modules from a light green to a dark teal color per the customer's request by targeting the custom class you assigned this module before saving it and using it on every page.

How to Style

Use the information below to learn how custom CSS class names or IDs should be assigned to modules.

Add a CSS ID or Class Name to a Module

You can enter a custom ID or class name for any row, column, or module, and that name can be used as a selector in any custom CSS rules that you write. 
To assign a custom CSS ID or class value to a row, column, or module:

  • Open a row, column, or module for editing.
  • Click the Advanced tab and scroll down to the HTML Element (Page Builder 2.x) or CSS Selectors (Page Builder 1.x) section.
  • Add a unique ID or a class name or both, depending on how you plan to use it. Don't use a pound sign or period in the value. The following sections describe ID and class selectors in more detail.
  • Multiple CSS classes can be entered by separating them with spaces.
About the ID selector

An ID selector must be unique, meaning it should only be used for only one element (meaning a row, column, or module).
IDs are used for two purposes:

  1. To write custom CSS rules that apply to a single element.
  2. To create an anchor so you can link to that element, for purposes such as scrolling down a page to a particular spot. (See the Related reference Article below for instructions on how to do that.)

Here are the rules for ID selectors:

  • They must start with a letter
  • They cannot contain spaces
  • The only characters they can use are letters, numbers, dashes, or underscores

The symbol used to refer to an ID selector in a CSS rule is the pound sign (#). For example, if you assign an ID named my-element to a module, you can target that ID by writing a CSS rule for #my-element.

The following rule says that the element with the ID "my-element" must be right-aligned:
#my-element { text-align: right; }

Note: You should use the pound sign to name IDs in your CSS rule, but you should not use the pound symbol when you assign the ID name to the row, column, or module.

About the class selector

The same class selector can be used with as many elements as you want your CSS rule to apply to.

A class selector has the same constraints as IDs in terms of the letters, numbers, and symbols it can contain.

Suppose you have several modules that you want to center on the page. Assign the same class name, my-elements, to each of the modules. 

The CSS symbol to refer to a class is a period (.), so your CSS rule would look like this:
.my-elements { text-align: center; }

Note: Keep in mind that classes in the CSS rule should start with a period, but the value you enter into the CSS setting for an element should not include the period.

Source: Beaver Builder KB - Add a CSS ID or class name to a module

Examples

Use the information below to learn how we can use custom class names/IDs to target modules and determine the correct amount of specificity to apply.

Specificity
When giving custom styled modules - especially ones you want to continue to use across the site - a custom class, its probably because you want to be able to make a simple change with CSS later on, to avoid having to adjust the styling in every single instance of the module across the site. In the case that we want to make a change to one module in particular that has been used once across the site, using CSS wont be necessary because you will be able to alter the module's styling in the builder within the single instance of its use...unless the style change you want to make doesn't exist as a modifiable property of the module's style tab.

Follow the below sequence to best style all instances of a module type using the custom CSS class assigned:
Custom class name given to module > class name of the section of module > class name of the item within the module you want to target

Task
"Target all H4 headings used across the site that are currently green, and make them blue."

  • Custom class name given to module: .green-heading
  • Module type: PowerPack Smart Headings
  • Class name belonging to component within the module you want to make changes to: span.title-text.pp-primary-title

Solution: 
Our goal is to use the least amount of specificity necessary to reflect the change, while still specifically targeting all H4 headings in modules given the custom class .green-heading, without using !important and without manually changing the style in every single instance of the module site-wide.

Solution:
.green-heading .pp-heading-content h4.heading-title span.title-text.pp-primary-title { color: #1976d2; }
  • Start with the custom class name given to the module: .green-heading
  • Select the component upon which the styling you want to change is currently applied: span.title-text.pp-primary-title
  • Try using 1 level of specificity as seen in image 2 - does it work? Why not?
  • Notice what classes are being used in the hierarchy for the style that is currently applied
  • The next level down from the top level class name of the module used in this hierarchy is: .pp-heading-content
  • One level down from that is the heading title - since we are only trying to target all H4 headings, we can use this too: h4.heading-title
  • Putting the first three levels together, along with the component being styled shows the color change being made as seen in image 3
  • In this case, this is the most specific we should get, using the least amount of specificity needed in order for the change to take place

CSS Placement

If CSS Could Play Hide & Seek...

Learn about the different places you can put custom styling when building a site... but where should you put it?
Note: The only place you should put any custom CSS you write during a build is in #3 The Customizer's Additional CSS Panel. If for some reason, you want to put CSS in another area discussed under #1 or #2, put a commented out note in the customizer telling the next builder where the CSS for that item can be found. It's still important to learn about the other areas you can put CSS in case there is a reason you encounter needing to use it or if you are troubleshooting a site, looking in all the places CSS could be put.

Restrict Custom CSS to a Single Beaver Builder Page

This procedure applies if you only want your CSS to apply to the content layout on a single Page Builder page. For example, suppose you have a contact form and know that you only want your custom CSS to apply to that form on that single page.

1. Set CSS Using Beaver Builder (for full PAGE Content Only)

You can add site-wide rules right in your Page Builder editing screen. The rules will apply to the content area of every page, whether or not the page or post is built with Page Builder. Don't use this location for rules that apply to areas controlled by your theme, such as header, footer, and sidebar. This method is very handy when you're adding custom ID or class selector names to individual rows, columns, or modules on a page, because you don't have to leave the page to add the rule and they still apply site-wide, and you can see the site-wide rules from any Page Builder editing page. On the other hand, you might prefer to keep all your rules in a single place so you can find them easily later. In that case, you one of the other methods below.

To add CSS and restrict it to a single Page Builder page or saved row/module/template:

  • In Beaver Builder editing mode, click the title bar in the upper left corner to open the Tools menu
  • Then click Layout CSS & JavaScript
  • On the CSS tab, enter your CSS code
  • Click Save

In GD Core, the saved templates for headers 1-8 for WooCommerce for example, have some template specific CSS in this area. These styles may apply to the cart module and search bar and there may be one fixing the of the positioning of WooCommerce notices when using a checkout page built with beaver builder.

Any pre-loaded header templates that have CSS in them can be found in this area when editing the header using Beaver Builder. If you want to remove this template-specific CSS once you select a header that has some, you can, but if you want to modify it, its recommended to cut it from this area and paste it in the Additional CSS panel of the customizer with your changes and a comment to specify what you changed.

Note: There is no good reason to use this area to put any CSS - use the customizer instead.
If for some reason, you want to put CSS here, put a commented out note in the customizer telling the next builder where the CSS for this region can be found. 

Apply Custom CSS Site-Wide

2. Using Beaver Builder (for ALL Content regardless of what it was built with)

This code will now appear in Tools > Global Settings on any Page Builder page, but the CSS rules will apply to all content areas of your site, whether or not they were built with Page Builder.

  • Click the title bar in the upper left corner to open the Tools menu
  • Then click Global Settings
  • On the CSS tab, enter your CSS code
  • Click Save and preview the result

Note: There is no good reason to use this area to put any CSS - use the customizer instead.
There is really no point to use this area at all considering the customizer is already technically considered site-wide and global.
If for some reason, you still want to put CSS here, put a commented out note in the customizer telling the next builder where the CSS for this region can be found.

3. Using The Customizer (Appearance > Customize > Additional CSS Tab)

This method applies the CSS code everywhere on your site: Page Builder and non-Page Builder content areas and any theme.

Note: USE THIS METHOD - All CSS you write during a new build should go here and this is where you should expect to find any custom styling.
In the rare event that you use some other place for custom CSS in your build, use this area to add a comment telling the next builder where they can find the custom CSS that you didn't include here and why you put it somewhere else.

The CSS you enter at Customize > Additional CSS is stored in the database. If a custom CSS rule contains a url attribute, the relative path to a file in your WordPress installation may need to change. In most cases, if you are pointing to any directory within the wp-content directory, the relative path should start with wp-content as seen here: 

See Image Path:
.some-row-or-something { background-image: url(/wp-content/uploads/2019/1/picture.jpg); }

Source: Beaver Builder KB - Where to put custom CSS code

Table of Contents
    Add a header to begin generating the table of contents
    Scroll To Top