Lucy Lucy - 1 year ago 244
jQuery Question

Google Sign In Website Using Custom Text

I have implemented Google Sign In for my website by following the official tutorial of Google :

Using the above tutorial I'm getting the following button

Google signin

Now I'm trying to Change the text of the button from "Sign In" to "Connect with Google" But nothing is happening..

My Javascript code..

function onSignIn(googleUser) {

var profile = googleUser.getBasicProfile();
loginpassword = profile.getId();
loginemail = profile.getEmail();

HTML Code..

<div class="g-signin2" data-onsuccess="onSignIn">Connect with Google</div>

Any idea how to change the text? Even though I'm providing the client ID and the external link for platform.js file it's still not working..Please Help..

Answer Source

The platform.js library from google is rendering the button, along with the text.

In order to override it, you need to build your own custom button. From Google's example:

  <link href="" rel="stylesheet" type="text/css">
  <script src=""></script>
  var googleUser = {};
  var startApp = function() {
    gapi.load('auth2', function(){
      // Retrieve the singleton for the GoogleAuth library and set up the client.
      auth2 = gapi.auth2.init({
        client_id: '',
        cookiepolicy: 'single_host_origin',
        // Request scopes in addition to 'profile' and 'email'
        //scope: 'additional_scope'

  function attachSignin(element) {
    auth2.attachClickHandler(element, {},
        function(googleUser) {
          document.getElementById('name').innerText = "Signed in: " +
        }, function(error) {
          alert(JSON.stringify(error, undefined, 2));
  <style type="text/css">
    #customBtn {
      display: inline-block;
      background: #4285f4;
      color: white;
      width: 190px;
      border-radius: 5px;
      white-space: nowrap;
    #customBtn:hover {
      cursor: pointer;
    span.label {
      font-weight: bold;
    span.icon {
      background: url('{{path to your button image}}') transparent 5px 50% no-repeat;
      display: inline-block;
      vertical-align: middle;
      width: 42px;
      height: 42px;
      border-right: #2265d4 1px solid;
    span.buttonText {
      display: inline-block;
      vertical-align: middle;
      padding-left: 42px;
      padding-right: 42px;
      font-size: 14px;
      font-weight: bold;
      /* Use the Roboto font that is loaded in the <head> */
      font-family: 'Roboto', sans-serif;

Once you've set the styles and the Javascript, you would call the button itself through HTML, at which point you can specify the text:

  <!-- In the callback, you would hide the gSignInWrapper element on a
  successful sign in -->
  <div id="gSignInWrapper">
    <span class="label">Sign in with:</span>
    <div id="customBtn" class="customGPlusSignIn">
      <span class="icon"></span>
      <span class="buttonText">Google</span>
  <div id="name"></div>

Note that you must comply with Google's branding guidelines.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download