Paramclasses Academy - Blog

Tutorials Details

←
Post 24 of 40
→

How to Add Custom CSS and JavaScript to a WordPress Website ?

How to Add Custom CSS and JavaScript to a WordPress Website ?

November 16, 2026

1. Introduction

WordPress provides themes, plugins, and built-in customization tools to design and manage websites. However, sometimes the available customization options are not enough to achieve a particular design or functionality.

For example:

  • You want to change the color of a button.

  • You want to add hover effects to navigation menus.

  • You want to customize website fonts and spacing.

  • You want to create an interactive button.

  • You want to display a message when a visitor clicks an element.

  • You want to add custom animations.

  • You want to implement a small frontend feature without installing another plugin.

You can achieve these tasks using Custom CSS and JavaScript.

CSS controls how website elements look, while JavaScript controls how website elements behave and interact with visitors.

In this tutorial, we will learn different methods of adding CSS and JavaScript to WordPress, with practical examples.

2. Understanding CSS

CSS stands for Cascading Style Sheets.

It is a stylesheet language used to control the visual presentation of HTML elements.

CSS can control:

  • Colors.

  • Fonts.

  • Backgrounds.

  • Borders.

  • Margins.

  • Padding.

  • Width and height.

  • Layouts.

  • Animations.

  • Responsive design.

Example: Basic CSS

h1 {
    color: blue;
    font-size: 36px;
    text-align: center;
}

Explanation

h1: Selects all HTML heading elements of level one.

color: Changes the text color.

font-size: Changes the text size.

text-align: Aligns the text.

CSS Syntax

selector {
    property: value;
}

For example:

p {
    color: #333333;
    font-size: 16px;
    line-height: 1.6;
}

Here:

  • p is the selector.

  • color is a property.

  • #333333 is its value.

  • font-size defines text size.

  • line-height defines spacing between lines.

Official CSS reference: https://developer.mozilla.org/en-US/docs/Web/CSS

3. Understanding JavaScript

JavaScript is a programming language used to make websites interactive and dynamic.

While CSS controls appearance, JavaScript controls behavior.

JavaScript can be used for:

  • Button click events.

  • Form interactions.

  • Dropdown menus.

  • Image sliders.

  • Popups.

  • Form validation.

  • Dynamic content.

  • Interactive navigation.

  • Frontend calculations.

Example: Basic JavaScript

alert("Welcome to Param Classes!");

When this JavaScript runs, the browser displays an alert message.

Example: JavaScript Button Click

<button onclick="showMessage()">
    Click Me
</button>

<script>
function showMessage() {
    alert("Welcome to Param Classes!");
}
</script>

When a visitor clicks the button, the JavaScript function executes.

4. Difference Between HTML, CSS and JavaScript

These three technologies work together to create interactive websites.

HTML

HTML provides the structure of a webpage.

Example:

<h1>Welcome to Param Classes</h1>

<p>Learn website development.</p>

<button>Get Started</button>

CSS

CSS controls the appearance.

h1 {
    color: #2271b1;
}

button {
    background: #2271b1;
    color: white;
    padding: 12px 20px;
}

JavaScript

JavaScript controls the behavior.

document.querySelector("button").addEventListener("click", function () {
    alert("Let's start learning!");
});

Remember:

  • HTML = Structure.

  • CSS = Design.

  • JavaScript = Functionality.

5. Understanding WordPress Customization Methods

WordPress provides different methods for adding custom CSS and JavaScript.

Methods for Adding Custom CSS

  1. WordPress Customizer – Additional CSS.

  2. Site Editor – Styles and custom CSS options where supported.

  3. Child Theme – style.css.

  4. Custom CSS Plugin.

  5. Page Builder – Custom CSS options where available.

Methods for Adding Custom JavaScript

  1. Child Theme – External JavaScript file.

  2. Custom JavaScript Plugin.

  3. Custom Plugin Development.

  4. Page Builder – Custom Code options where available.

  5. WordPress enqueue functions.

Important: The available customization options depend on your WordPress theme, hosting environment, WordPress version, and user permissions.

6. Method 1: Add Custom CSS Using WordPress Customizer

This is one of the easiest methods for adding custom CSS to a classic WordPress theme.

Step 1: Login to WordPress Dashboard

Open:

http://localhost/yourwebsite/wp-admin

Enter your administrator username and password.

Step 2: Open the Customizer

Navigate to:

Appearance → Customize

The WordPress Customizer will open.

Step 3: Find Additional CSS

Locate the Additional CSS option.

Click it to open the CSS editor.

Step 4: Add Custom CSS

Enter the following code:

body {
    background-color: #f5f7fa;
}

h1 {
    color: #2271b1;
    text-align: center;
}

p {
    font-size: 16px;
    line-height: 1.6;
}

Step 5: Publish Changes

Click Publish.

Open your website in another browser tab and refresh it.

You should see the updated styling wherever these selectors match.

Note: Some modern block themes use the Site Editor instead of the traditional Customizer. If Additional CSS is not available, check the theme's Styles interface or use a suitable child theme or CSS management tool.

7. Method 2: Add Custom CSS Using the WordPress Site Editor

Block themes use the Full Site Editing system.

You can customize supported global design settings through the Site Editor.

Step 1: Open Site Editor

Navigate to:

Appearance → Editor

Step 2: Open Styles

Select the Styles option.

You can customize:

  • Typography.

  • Colors.

  • Layout.

  • Background.

  • Block appearance.

Step 3: Customize Website Design

For example, change the global text and background colors.

You can also customize individual block styles.

Step 4: Save Changes

Click Save.

Review the changes on your website.

Important: The Site Editor provides visual design controls, but a dedicated raw CSS editor is not available in exactly the same way in every WordPress installation. For additional CSS rules, use a compatible theme feature, child theme, or CSS management plugin.

8. Method 3: Add Custom CSS Using a Plugin

If your theme does not provide a convenient CSS editor, you can use a custom CSS plugin.

One example is Simple Custom CSS and JS.

Step 1: Open Add Plugins

Navigate to:

Plugins → Add New Plugin

Step 2: Search for the Plugin

Search for:

Simple Custom CSS and JS

Step 3: Install the Plugin

Click Install Now.

Step 4: Activate the Plugin

Click Activate.

Step 5: Open Custom CSS

Open the plugin's Custom CSS section.

Select Add CSS Code.

Step 6: Enter Your CSS

Example:

.custom-heading {
    color: #2271b1;
    font-size: 32px;
    font-weight: 700;
    text-align: center;
}

.custom-button {
    background-color: #2271b1;
    color: #ffffff;
    padding: 12px 25px;
    border-radius: 6px;
}

Step 7: Publish the CSS

Save or publish the code using the plugin's available controls.

Visit your website and test the result.

Official plugin page: https://wordpress.org/plugins/custom-css-js/

9. Understanding CSS Selectors

Before adding custom CSS, you should understand how CSS selectors identify HTML elements.

9.1 Element Selector

Selects HTML elements by their tag name.

h1 {
    color: red;
}

This selects all h1 elements.

9.2 Class Selector

A class selector starts with a dot.

.my-heading {
    color: blue;
}

HTML:

<h1 class="my-heading">
    Welcome to Param Classes
</h1>

9.3 ID Selector

An ID selector starts with a hash symbol.

#main-heading {
    color: green;
}

HTML:

<h1 id="main-heading">
    WordPress Development
</h1>

9.4 Descendant Selector

Selects elements inside another element.

.header a {
    color: white;
}

This selects anchor elements inside an element with the header class.

9.5 Hover Selector

Applies styling when the visitor moves the mouse over an element.

.custom-button:hover {
    background-color: #135e96;
    transform: translateY(-2px);
}

9.6 Responsive Media Query

Media queries allow CSS to change according to screen conditions.

@media (max-width: 768px) {

    h1 {
        font-size: 26px;
    }

    .custom-button {
        width: 100%;
    }

}

This CSS applies when the viewport width is 768 pixels or smaller.

10. Practical CSS Project: Customize a WordPress Website

Now we will create a simple professional design using custom CSS.

Objective

Customize the appearance of a heading, paragraph, and button.

Step 1: Add HTML Using a Custom HTML Block

Open a WordPress page.

Add a Custom HTML block.

Insert:

<div class="param-section">

    <h2 class="param-heading">
        Learn WordPress Development
    </h2>

    <p class="param-description">
        Build professional websites with practical
        development tutorials at Param Classes.
    </p>

    <a href="#" class="param-button">
        Start Learning
    </a>

</div>

Step 2: Add Custom CSS

Open Additional CSS or your preferred CSS editor.

Insert:

.param-section {
    text-align: center;
    padding: 50px 20px;
    background: #f5f7fa;
    border-radius: 12px;
}

.param-heading {
    color: #17365d;
    font-size: 34px;
    margin-bottom: 15px;
}

.param-description {
    color: #555555;
    font-size: 17px;
    line-height: 1.7;
    max-width: 650px;
    margin: 0 auto 25px;
}

.param-button {
    display: inline-block;
    padding: 13px 28px;
    background: #2271b1;
    color: #ffffff;
    text-decoration: none;
    border-radius: 6px;
    transition: 0.3s ease;
}

.param-button:hover {
    background: #135e96;
    transform: translateY(-3px);
}

@media (max-width: 768px) {

    .param-heading {
        font-size: 26px;
    }

    .param-description {
        font-size: 15px;
    }

}

Step 3: Save the Page

Click Update.

Open the page on the frontend.

You should see a customized section with:

  • Centered heading.

  • Styled paragraph.

  • Professional button.

  • Hover effect.

  • Responsive text sizes.

11. How to Add Custom JavaScript Using a Plugin

For beginners, a custom JavaScript plugin provides a convenient way to manage scripts without editing theme files.

Step 1: Install a Custom JavaScript Plugin

Navigate to:

Plugins → Add New Plugin

Search for:

Simple Custom CSS and JS

Install and activate it if it is not already installed.

Step 2: Open Custom JS

Navigate to the plugin's Custom JS section.

Click Add JS Code.

Step 3: Enter a Title

Example:

Param Classes Button Interaction

Step 4: Add JavaScript

Insert:

document.addEventListener("DOMContentLoaded", function () {

    const button = document.querySelector(".param-button");

    if (button) {

        button.addEventListener("click", function (event) {

            event.preventDefault();

            alert("Welcome to Param Classes!");

        });

    }

});

Step 5: Configure Script Placement

If the plugin provides placement options, select a suitable frontend location.

For this example, loading the script in the footer is generally appropriate.

Make sure the script is enabled on the frontend.

Step 6: Save and Publish

Save the JavaScript code.

Open the page containing the .param-button element.

Click the button.

You should see:

Welcome to Param Classes!

Note: The example prevents the link's default navigation only to demonstrate the click interaction. In a real website, do not use event.preventDefault() if the button is supposed to navigate to another page.

12. Method 2: Add JavaScript Using a Child Theme

For developers, adding JavaScript through a child theme is a structured approach.

It allows you to maintain custom code separately from the parent theme.

Step 1: Understand the Child Theme Directory

Example:

wp-content/
│
└── themes/
    │
    ├── parent-theme/
    │
    └── parent-theme-child/
        │
        ├── style.css
        ├── functions.php
        │
        └── js/
            └── custom.js

Step 2: Create the JavaScript File

Inside your child theme, create:

js/custom.js

Add the following code:

document.addEventListener("DOMContentLoaded", function () {

    console.log("Param Classes JavaScript Loaded");

});

Save the file.

Step 3: Open functions.php

Open the child theme's functions.php file.

Add:

<?php

function param_classes_custom_scripts() {

    wp_enqueue_script(
        'param-custom-script',
        get_stylesheet_directory_uri() . '/js/custom.js',
        array(),
        '1.0.0',
        array(
            'in_footer' => true
        )
    );

}

add_action(
    'wp_enqueue_scripts',
    'param_classes_custom_scripts'
);

If your functions.php already starts with <?php, do not add another opening PHP tag.

Step 4: Save the File

Save your changes.

Open the WordPress website.

Step 5: Check the Browser Console

Open the website in Chrome.

Right-click and select Inspect.

Open the Console tab.

You should see:

Param Classes JavaScript Loaded

This confirms that the JavaScript file has loaded and executed.

Important: Never edit the parent theme's files directly. Parent theme updates may overwrite your changes. Use a child theme or a custom plugin for code that must survive theme updates.

13. Method 3: Add Custom CSS and JavaScript Using WordPress Enqueue Functions

WordPress provides built-in functions for loading stylesheets and scripts.

The recommended functions are:

  • wp_enqueue_style() – Loads a CSS stylesheet.

  • wp_enqueue_script() – Loads a JavaScript file.

These functions allow WordPress to manage script dependencies and loading order.

13.1 Understanding wp_enqueue_style()

Example:

wp_enqueue_style(
    'param-custom-style',
    get_stylesheet_directory_uri() . '/css/custom.css',
    array(),
    '1.0.0',
    'all'
);

Explanation:

param-custom-style: Unique stylesheet handle.

get_stylesheet_directory_uri(): Returns the active stylesheet directory URL, which is useful for a child theme.

/css/custom.css: Path to the CSS file.

array(): Stylesheet dependencies.

1.0.0: Version number.

all: Media type.

13.2 Understanding wp_enqueue_script()

Example:

wp_enqueue_script(
    'param-custom-script',
    get_stylesheet_directory_uri() . '/js/custom.js',
    array(),
    '1.0.0',
    array(
        'in_footer' => true
    )
);

Explanation:

param-custom-script: Unique script handle.

get_stylesheet_directory_uri(): Returns the active child theme directory URL.

/js/custom.js: JavaScript file path.

array(): Script dependencies.

1.0.0: Version number.

in_footer: Requests that the script be loaded in the footer.

13.3 Complete Example

Add this code to your child theme's functions.php file:

<?php

function param_classes_enqueue_assets() {

    wp_enqueue_style(
        'param-custom-style',
        get_stylesheet_directory_uri() . '/css/custom.css',
        array(),
        '1.0.0',
        'all'
    );

    wp_enqueue_script(
        'param-custom-script',
        get_stylesheet_directory_uri() . '/js/custom.js',
        array(),
        '1.0.0',
        array(
            'in_footer' => true
        )
    );

}

add_action(
    'wp_enqueue_scripts',
    'param_classes_enqueue_assets'
);

This function loads both CSS and JavaScript files on the frontend.

Make sure the following files actually exist:

parent-theme-child/
│
├── functions.php
│
├── css/
│   └── custom.css
│
└── js/
    └── custom.js

The code will not load missing files.

Official documentation:
https://developer.wordpress.org/themes/core-concepts/including-assets/

14. Practical JavaScript Project: Create a Read More Button

Now we will create a simple interactive Read More feature.

Step 1: Add HTML

Open a WordPress page and add a Custom HTML block.

Insert:

<div class="read-more-section">

    <p id="extra-content" hidden>
        Welcome to Param Classes. Learn WordPress,
        PHP, JavaScript and modern website development
        with practical projects and tutorials.
    </p>

    <button id="read-more-btn" type="button">
        Read More
    </button>

</div>

Step 2: Add CSS

Insert the following CSS:

#extra-content {
    margin-top: 15px;
    color: #444444;
    line-height: 1.7;
}

#read-more-btn {
    background: #2271b1;
    color: #ffffff;
    border: none;
    padding: 12px 25px;
    border-radius: 5px;
    cursor: pointer;
}

#read-more-btn:hover {
    background: #135e96;
}

Step 3: Add JavaScript

Add this code using your JavaScript management method:

document.addEventListener("DOMContentLoaded", function () {

    const button = document.getElementById("read-more-btn");
    const content = document.getElementById("extra-content");

    if (button && content) {

        button.addEventListener("click", function () {

            content.hidden = !content.hidden;

            button.textContent = content.hidden
                ? "Read More"
                : "Read Less";

        });

    }

});

Step 4: Save and Test

Update your page.

Open the frontend.

Initially, the additional content is hidden.

When the visitor clicks Read More:

  • The hidden paragraph becomes visible.

  • The button changes to Read Less.

When the visitor clicks Read Less:

  • The paragraph becomes hidden again.

  • The button returns to Read More.

Understanding the JavaScript

DOMContentLoaded

Waits until the HTML document has been parsed.

getElementById()

Finds an HTML element using its ID.

addEventListener()

Registers an event handler.

click

Detects when the visitor clicks the button.

hidden

Controls whether the HTML element is hidden.

textContent

Changes the text displayed inside the button.

This practical example demonstrates how JavaScript can add interactivity to a WordPress website.

15. Important WordPress JavaScript Concepts

15.1 DOM

DOM stands for Document Object Model.

It represents the webpage as a structured object tree that JavaScript can access and modify.

Example:

document.querySelector("h1").textContent =
    "Welcome to Param Classes";

This changes the text of the first matching h1 element.

15.2 Event Listener

An event listener allows JavaScript to respond to user actions.

Example:

document.querySelector("button").addEventListener(
    "click",
    function () {

        console.log("Button Clicked");

    }
);

15.3 Console

The browser console helps developers debug JavaScript.

Example:

console.log("JavaScript is working");

To open it:

  1. Open your website.

  2. Right-click.

  3. Select Inspect.

  4. Click Console.

15.4 jQuery in WordPress

WordPress includes jQuery as a bundled library.

If your code requires jQuery, declare it as a dependency when enqueueing your script.

Example:

wp_enqueue_script(
    'param-jquery-script',
    get_stylesheet_directory_uri() . '/js/custom.js',
    array('jquery'),
    '1.0.0',
    array(
        'in_footer' => true
    )
);

Inside your JavaScript file, you can use:

jQuery(document).ready(function ($) {

    console.log("jQuery is working");

});

Always declare dependencies correctly instead of assuming that another plugin has already loaded jQuery.

16. Common CSS and JavaScript Problems

Problem 1: Custom CSS Is Not Working

Possible reasons:

  • Incorrect selector.

  • CSS syntax error.

  • Theme styles overriding custom CSS.

  • Browser cache.

  • Wrong stylesheet location.

Solutions:

  1. Check the selector.

  2. Verify CSS syntax.

  3. Inspect the element using browser developer tools.

  4. Check computed styles.

  5. Clear the relevant cache.

  6. Verify that the stylesheet is loading.

Problem 2: JavaScript Is Not Working

Possible reasons:

  • Incorrect JavaScript syntax.

  • Wrong file path.

  • Script not enqueued.

  • JavaScript runs before the HTML element exists.

  • Another script creates an error.

Solutions:

  1. Open the browser console.

  2. Check for JavaScript errors.

  3. Verify the script URL in the Network tab.

  4. Use DOMContentLoaded when appropriate.

  5. Check the selector and element ID.

  6. Review script dependencies.

Problem 3: CSS Changes Are Not Visible

Possible reasons:

  • Cached CSS.

  • CDN cache.

  • Minified CSS.

  • Wrong theme or stylesheet.

Solutions:

  • Clear plugin cache.

  • Clear browser cache.

  • Purge CDN cache if applicable.

  • Inspect the actual loaded stylesheet.

  • Test in a private browser window.

Problem 4: JavaScript Button Is Not Responding

Possible reasons:

  • Incorrect button ID.

  • Missing event listener.

  • Script loading failure.

  • JavaScript error.

Solutions:

  • Check the HTML ID.

  • Check the JavaScript selector.

  • Verify that the script is loaded.

  • Review browser console errors.

Problem 5: Website Design Breaks After Adding CSS

Possible reasons:

  • Broad CSS selectors.

  • Incorrect CSS properties.

  • Overriding theme styles.

  • Fixed dimensions.

Solutions:

  • Use specific class names.

  • Avoid unnecessary global selectors.

  • Use responsive CSS.

  • Test desktop, tablet, and mobile layouts.

17. Best Practices for Adding Custom CSS and JavaScript

  1. Use a child theme for persistent theme-level customizations.

  2. Use a custom plugin when functionality should remain independent of the active theme.

  3. Prefer WordPress enqueue functions for external CSS and JavaScript files.

  4. Use unique class names and IDs.

  5. Avoid modifying WordPress core files.

  6. Avoid directly editing parent theme files.

  7. Keep CSS and JavaScript organized in separate files.

  8. Use meaningful function names and script handles.

  9. Test changes on a staging website.

  10. Check browser console errors.

  11. Use responsive CSS.

  12. Avoid loading unnecessary JavaScript libraries.

  13. Declare script dependencies correctly.

  14. Back up your website before major changes.

  15. Keep custom code documented.

Developer Tip: If you are adding a feature that must continue working after changing your WordPress theme, consider creating a small custom plugin instead of placing the functionality in a theme's functions.php file.

18. Practical Assignment: Customize a WordPress Website

Now complete this practical project on your WordPress website.

Assignment Objective

Create a customized website section with CSS styling and JavaScript functionality.

Task 1: Create a Custom Section

Add:

  • Main heading.

  • Description.

  • Call-to-action button.

  • Additional hidden content.

Task 2: Apply CSS

Customize:

  • Background color.

  • Heading color.

  • Font size.

  • Button design.

  • Border radius.

  • Hover effect.

  • Mobile responsiveness.

Task 3: Add JavaScript

Implement:

  • Button click event.

  • Read More and Read Less functionality.

  • Dynamic button text.

  • Console debugging.

Task 4: Use WordPress Enqueue Functions

Create:

  • css/custom.css

  • js/custom.js

Load both files through your child theme's functions.php.

Task 5: Test Your Website

Check:

  • CSS is loading correctly.

  • JavaScript is executing.

  • Button click works.

  • Content visibility changes.

  • Website works on mobile.

  • No console errors are present.

Expected Output

At the end of this assignment, you should have:

  • A professionally styled website section.

  • Custom CSS successfully applied.

  • A working JavaScript interaction.

  • External CSS and JS files.

  • A correctly configured WordPress enqueue function.

19. Frequently Asked Questions (FAQs)

Q1. What is Custom CSS in WordPress?

Custom CSS allows developers to modify the appearance of WordPress websites without editing the original theme stylesheets.

Q2. Where can I add Custom CSS in WordPress?

You can use Additional CSS in the Customizer when available, a compatible Site Editor or theme feature, a child theme, or a CSS plugin.

Q3. Can I add JavaScript directly to WordPress?

Yes. You can add JavaScript using a compatible plugin, child theme, custom plugin, or supported page-builder custom-code feature.

Q4. What is the difference between CSS and JavaScript?

CSS controls visual appearance, while JavaScript controls dynamic behavior and interactions.

Q5. What is a child theme?

A child theme inherits functionality and styling from a parent theme while allowing developers to add customizations separately.

Q6. What is wp_enqueue_style()?

It is a WordPress function used to register and load CSS stylesheets.

Q7. What is wp_enqueue_script()?

It is a WordPress function used to register and load JavaScript files.

Q8. Why should developers use enqueue functions?

They allow WordPress to manage dependencies, loading order, and script or stylesheet registration more reliably.

Q9. Can Custom CSS break a WordPress website?

Incorrect CSS can cause layout and responsive design problems, but it generally does not execute PHP or directly modify WordPress database content.

Q10. Can JavaScript affect WordPress functionality?

Yes. Incorrect JavaScript can break frontend interactions, forms, menus, and other website features.

20. Conclusion

Custom CSS and JavaScript provide developers with greater control over WordPress website design and functionality.

In this tutorial, you learned:

  • What CSS and JavaScript are.

  • How HTML, CSS, and JavaScript work together.

  • How to add CSS using the Customizer.

  • How to use the WordPress Site Editor.

  • How to add CSS using a plugin.

  • How to add JavaScript using a plugin.

  • How to use a child theme.

  • How to use WordPress enqueue functions.

  • How to create interactive buttons.

  • How to troubleshoot CSS and JavaScript problems.

  • How to follow professional development practices.

By completing the practical assignment, you will gain hands-on experience customizing WordPress websites using frontend technologies.

←
Post 24 of 40
→