function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

styleClass does not work with apex:commandButton

Hi all,


I am trying to use the styleClass attribute to apply a specific style to a button but it doesn't work.

When I apply the same style inline in the tag it works.


The tag is <apex:commandButton>, any hint?


(I only managed so far  to modify the background colour of the button inline)

Thanks for explaining me what can be wrong in my code:


<apex:page >

    <style type="text/css"> 
      .myClass {

<apex:commandButton styleClass="myClass" action="{!someAction}">  

Best Answer chosen by Admin (Salesforce Developers) 
<style type="text/css">
color:white !important;
background:#00CC00 !important;


All Answers


Hi Just put 

<apex:page standardStylesheet="false">

It will work. If it does not work pleaselet me know.




Style class doesn't support , you have to try this

<div class="myclass"><apex:commandButton action="{!someAction}" value="action"/></div>

I have solved this myself by adding the CSS !important annotation.


standardStylesheets = false did not work.


Nesting the button in a <div> had the background colour overlapping in an entire line, which I did not want

<style type="text/css">
color:white !important;
background:#00CC00 !important;


This was selected as the best answer
My code is 
.buttonStyle {
<apex:commandButton value="Save" styleClass="buttonStyle" style="background:blue" action="{!Truethat}"/>

I see that the color of my button is changing , but I am not able to see the change in the font color. 
Can anyne suggest me how to change the code so that the font color cn alos be changed aling with the background color of the button. 

Thank you
Mustafa JhabuawalaMustafa Jhabuawala
@Nimesh: Your style class .buttonStyle is not working in your case and the blue color is applied through the inline styling used in the apex:commandbutton tag.

For font color you can add inline css code as style="background:blue; color:white" 
Nirmal Garg 20Nirmal Garg 20
<apex:page standardStylesheets="false" >
        .submit {
      cursor: pointer;
        border-radius: 5em;
        color: #fff;
        background: linear-gradient(to right, #9C27B0, #E040FB);
        border: 0;
        padding-left: 40px;
        padding-right: 40px;
        padding-bottom: 10px;
        padding-top: 10px;
        font-family: 'Ubuntu', sans-serif;
        margin-left: 35%;
        font-size: 13px;
        box-shadow: 0 0 20px 1px rgba(0, 0, 0, 0.04);
            <apex:commandButton value="Save" styleClass="submit"/>