Recaptcha: ReCaptcha is not really responsive.

Created on 10 Aug 2015  Â·  78Comments  Â·  Source: google/recaptcha

As I have the problem now, the recaptcha has a fixed size and should be responsive. Here is a bug ticket from februrary: https://code.google.com/p/recaptcha/issues/detail?id=215

widget

Most helpful comment

Why is this not being fixed? A lot of websites are responsive, and a lot of traffic goes via mobile devices. It makes no sense that recaptcha is not responsive as well.

All 78 comments

It's too bad it isn't responsive indeed. The only decent workaround I have found so far is scaling the whole thing down a bit with css transform.

You can also try specifying the data-size="compact" attribute. Though, this does only affect the initial display of the widget, not the potential additional UI if further verification is needed.

The image select box is now broken with an annoying text area :disappointed:, hoping someone can submit a fix.

@huynhquancam do you have a screenshot or a way to reproduce?

@rowan-m thanks, here is the screenshot from my localhost

screen shot 2015-08-20 at 9 43 11 pm

and also the HTML generated

<div class="form-group">
  <script src="//www.google.com/recaptcha/api.js" async="" defer=""></script>
  <div class="g-recaptcha" data-sitekey="XXX">
    <div>
      <div style="width: 302px; height: 422px; position: relative;">
        <div style="width: 302px; height: 422px; position: absolute;">
          <iframe src="https://www.google.com/recaptcha/api/fallback?k=XXX&amp;hl=en&amp;v=r20150812220525&amp;t=1&amp;ff=true" frameborder="0" scrolling="no" style="width: 302px; height:422px; border-style: none;"></iframe>
        </div>
      </div>
      <div style="border-style: none; bottom: 12px; left: 25px; margin: 0px; padding: 0px; right: 25px; background: #f9f9f9; border: 1px solid #c1c1c1; border-radius: 3px; height: 60px; width: 300px;">
        <textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid #c1c1c1; margin: 10px 25px; padding: 0px; resize: none; "></textarea>
      </div>
    </div>
  </div>
  <noscript>&lt;div style="width: 302px; height: 352px;"&gt;  &lt;div style="width: 302px; height: 352px; position: relative;"&gt;    &lt;div style="width: 302px; height: 352px; position: absolute;"&gt;      &lt;iframe src="//www.google.com/recaptcha/api/fallback?k=XXX"                frameborder="0" scrolling="no"                style="width: 302px; height:352px; border-style: none;"&gt;        &lt;/iframe&gt;      &lt;/div&gt;      &lt;div style="width: 250px; height: 80px; position: absolute; border-style: none;              bottom: 21px; left: 25px; margin: 0px; padding: 0px; right: 25px;"&gt;        &lt;textarea id="g-recaptcha-response" name="g-recaptcha-response"                   class="g-recaptcha-response"                   style="width: 250px; height: 80px; border: 1px solid #c1c1c1;                   margin: 0px; padding: 0px; resize: none;" value=""&gt;         &lt;/textarea&gt;      &lt;/div&gt;    &lt;/div&gt;  &lt;/div&gt;</noscript>
</div>

Here is a hack that worked for me:

.gc-reset{
transform:scale(0.95) !important;
-webkit-transform:scale(0.95) !important;
transform-origin:0 0 !important;
-webkit-transform-origin:0 0 !important;
}

gc-reset is a class that is used in three wrappers around the imageselect, so the transform is applied three times.

@recfish That's how I did it as well, not very beautiful but it works.

Why is this not being fixed? A lot of websites are responsive, and a lot of traffic goes via mobile devices. It makes no sense that recaptcha is not responsive as well.

I really agree with that but for me, as a workaround the scale thing was working for me.

Hopefully scaling this will work across devices but seriously.... Why isn't this fixed yet????

+1... It's sort of unbelievable that this is not responsive. And what's with the id-less, class-less div wrapping the iframe with a set width? or is that just the rails Gem doing that??

+1 It's really not responsive :/ , Any news?

For Bootstrap 3 (+ 480px breakpoint hack) the following code (written in SCSS) partially solved my problem:

// Extra small (<480px)
@media(max-width: $screen-xs-max){
  .g-recaptcha iframe {
    max-width: 100%;
    transform:scale(0.77);
    -webkit-transform:scale(0.77);
    transform-origin: center center;
    -webkit-transform-origin: center center;
  }
  #rc-imageselect {
    transform:scale(0.77);
    -webkit-transform:scale(0.77);
    transform-origin:0 0;
    -webkit-transform-origin:0 0;
  }
}

// Medium small (>=480px)
@media(min-width: $screen-ms-min){
  #rc-imageselect {
    transform: none;
    -webkit-transform: none;
  }

  .g-recaptcha iframe {
    max-width: none;
    transform: none;
    -webkit-transform: none;
  }
}

// Horizontally center the recaptcha - applied to all widths
.g-recaptcha > div > div{
  margin: 4px auto !important;
  text-align: center;
  width: auto !important;
  height: auto !important;
}

This code will horizontally center your recaptcha and scale it when width less than 480px. However, this code also hides part of the recaptcha when you have a device with less than ~403px wide.

There's anyone here with more css skills than I that can solve this problem?

Code based on How to resize the Google noCAPTCHA reCAPTCHA. Btw Google, please implement responsiveness support.

Any plans or update if and when it would be made responsive? @rowan-m

My solution is a pure JS approach. Using jquery + bootstrap 3 (img-responsive class).. though im sure it's quite easy to pull out that little bit of css related to img-responsive.

var recaptchaCallback = function () {
    $('.g-recaptcha').each(function() {
                var rc = grecaptcha.render(this, {
          'sitekey' : ..,
          'theme': ..,
          'callback': ..
                });

               $(this).find('iframe:first')
               .removeAttr('width')
               .addClass('img-responsive')
               .parent()
               .css('width', 'auto');
        });
};

On small smartphones (iPhone 3, S3 mini) it's even worse: the re-captcha container gets cut off on the right. A lot of our mobile visitors still use these kind of small smartphones. It's actually quite unbelievable that Google, the creator of so many great frameworks and fierce supporter of mobile front-ends, is not capable of or willing to do a responsive re-captcha.

Just label this: won't fix

@goldhand because of? There should be a reason for doing a won't fix. All the solutions are workarounds for me.

@goldhand @Chris2011: There's indeed no solution yet, it should be fixed. Right now it's little hacks and workarounds. And when the test is displayed it's completely broken. I don't understand how this bug is still open after all these months.

@Chris2011 sorry for my sarcasm. It's been almost a year since this issue's been open but that's not an excuse to be negative.

@goldhand ok no problem :)

Hoping someone at google is paying attention, adding my 2 cents it needs to be fixed, maybe more voices is good, no knowing...

+1 yes. it would be awesome if the responsiveness coud be enhanced.

Always responsive issues with google. Had similar issues with google ads not being responsive. Adding another comment so this issue hopefully gets fixed without the need for a work around.

Got it working with this code.

`
@media screen and (max-height: 575px){

rc-imageselect, .g-recaptcha {

transform:scale(0.77);
-webkit-transform:scale(0.77);
transform-origin:0 0;
-webkit-transform-origin:0 0;
}`

Thank you so much... This code works great...

Warm regards...

Such code was still mentioned comments before. See https://github.com/google/recaptcha/issues/61#issuecomment-220029290 and https://github.com/google/recaptcha/issues/61#issuecomment-150051192

I suspect most here are more code savvy than I, so I hesitate a bit, but offer that this code was easy to try, goes after the height rather than width so maybe hopefully includes some different phone widths, not just my iPhone 5s, is less involved than the linked to code, and does it perfectly for me... I just needed to tweak the scale a bit for my eye...

Kind regards...

I can pull request the css fix of @MiticoMedia, if that's welcome?

@sailingdeveloper, my vote would be not to merge a CSS hack. Is it not possible to remove whatever code that is explicitly setting the width and height? Perhaps make it possible to pass an options hash?

Hey all, sorry for being quiet on this! A few bits for you…

Firstly, this repo is actually just the PHP code that provides a client to the reCAPTCHA service. It is not responsible for any rendering of the widget. I've gone through and labelled all the issues that are referencing something that would not be affected by changes in this repo. I will go through the widget issues though and pass these on to internal issues where appropriate.

I'll carve out some time to go through these properly and start addressing the PHP issues then get another release out. I'm also happy to add a FAQ or similar with CSS tips however I have to caveat that externally altering the appearance of the widget is fragile since it obviously it may change and any CSS applied externally may have an unintended effect.

Thank you for getting back and for your intentions here... Clearly fixes for this and the other issues you have labelled need to be applied internally as you indicate... Wishing that to go well... And, a CSS FAQ would be nice to have, appreciated...

@rowan-m thanks for your comment although it doesn't really answer the main question -- will recpatcha be made more responsive? It's one thing that puts me off using it at all because it's pretty much unusable on mobile at the moment.

@jayesbe Your solution seemed to be the only one to be promising for a responsive website and fluid layouts, so I've created a tiny solution with jQuery for django-cms, as this has been my current need:

Maybe my Stackoverflow answer is of use to somebody.

Sorry my bad english.
Is the version I use for Joomla-k2 and works perfectly for my:

.k2-recaptcha-v2{
    margin: 0 !important;
    margin-top: 15px !important;
}
.g-recaptcha > div,
.k2-recaptcha-v2 > div {
    width: 100% !important;
}

.g-recaptcha > div > div,
.k2-recaptcha-v2 > div > div {
    margin: 4px auto !important;
    /*text-align: center;*/
    width: auto !important;
    height: auto !important;
}

.g-recaptcha iframe,
.k2-recaptcha-v2 iframe {
    transform: scale(0.85);
    -webkit-transform: scale(0.85);
    transform-origin: left top;
    -webkit-transform-origin: left top;
}
#rc-imageselect {
    transform:scale(0.77);
    -webkit-transform:scale(0.77);
    transform-origin:0 0;
    -webkit-transform-origin:0 0;
}

/*-- Pantallas superiores a 480px --*/
@media(min-width: 480px){
  #rc-imageselect {
    transform: none;
    -webkit-transform: none;
  }

  .g-recaptcha iframe,
  .k2-recaptcha-v2 iframe{
    max-width: none;
    transform: none;
    -webkit-transform: none;
  }
}

is this going to be addressed? it's a major problem with recaptcha and here we are 2 years later

This is so annoying. Please fix this, playing arround with scale and margin to fit it probably should not be needed.

How has this not been fixed yet?

@klombomb Last thing they told me (somewhere in the end of 2015) was that it's "out of scope" for this specific repo/project. But they were going to pass it on to the design/product team.

@wouterds Ironic that a company promoting progressive web apps all the time isn't bothered to make one of their most popular developer services responsive.

@klombomb: The best _"solution"_ available at this time is scaling the whole thing down using css transform: scale(0.95) !important;.

Hi,
I've found a solution for this you can find it here. and pls comment it also for below link's post
http://webprow.com/blog/recaptcha-v2-responsive/

The solution was the scaling thing and it was mentioned often before @gobi004

All of these are workarounds @google-admin

I fixed the problem without any extra css ,
just set the div width:100% , also I remove iframe overflow:hidden .

Any CSS trick doesn't work for me.

+1 to a fix

Booo fix it, there is irony in punishing indexing for lacking mobile compatible websites

@MohanadI not sure how it helped you
image

Here is the best workaround I have found :

.g-recaptcha > div {
    width: 100% !important;
}

.g-recaptcha iframe {
    width: 100% !important;
}

bump

👎

capture

http://webprow.com/blog/recaptcha-v2-responsive/

On Wed, Jan 31, 2018 at 4:09 PM, Abhigyan Tiwari notifications@github.com
wrote:

👎

[image: capture]
https://user-images.githubusercontent.com/16822592/35618443-03b49c56-06a1-11e8-9fcf-7fc5d4d23702.PNG

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/recaptcha/issues/61#issuecomment-361892851,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AT2fUdVXBNMOka0q_84jA157YI3Vg_66ks5tQELfgaJpZM4Fo_M9
.

--
Gobinath.B - Freelance web developer

Website : Webprow http://webprow.com/

I think you guys don't understand how complex this development is. Changing width must involve thousands of hours of hard work and cutting edge skills. Remember adding color on a text in CSS? It's even worse.
Plus it's not like it's really important, today browsing on mobile phones is so overrated, I think people are not ready for it.

@bmalaud are you serious?

@Jimmaki I don't think so ;)

Here is JavaScript code using jQuery to do so:

$(document).ready(function () {        
    var width = $('.g-recaptcha').parent().width();
    if (width < 302) {
        var scale = width / 302;
        $('.g-recaptcha').css('transform', 'scale(' + scale + ')');
        $('.g-recaptcha').css('-webkit-transform', 'scale(' + scale + ')');
        $('.g-recaptcha').css('transform-origin', '0 0');
        $('.g-recaptcha').css('-webkit-transform-origin', '0 0');
    }
});

IMP Note : It will support All Devices, above and bellow 320px width as well.

@ParmarVjay Thank you - this works. In my application, I also ran it on window resize so that reCaptcha remains responsive when container width changes.

function resizeReCaptcha() {
  var width = $('.g-recaptcha').parent().width();
  if (width < 302) {
      var scale = width / 302;
      $('.g-recaptcha').css('transform', 'scale(' + scale + ')');
      $('.g-recaptcha').css('-webkit-transform', 'scale(' + scale + ')');
      $('.g-recaptcha').css('transform-origin', '0 0');
      $('.g-recaptcha').css('-webkit-transform-origin', '0 0');
  }
};
$(document).ready(function() {
  $(window).on('resize', function(){
    resizeReCaptcha();
  });
  resizeReCaptcha();
});

@ParmarVjay Added your snippet just before didn't do anything.
Should I place it instead in the ?

To expand on @tomanistor, I added a part to resize back to normal if the screen is wide enough (for example, flipping from portrait to landscape and vice versa).

function resizeReCaptcha() {

  var width = $( ".g-recaptcha" ).parent().width();

  if (width < 302) {
      var scale = width / 302;
  } else {
      var scale = 1;
  }

  $( ".g-recaptcha" ).css('transform', 'scale(' + scale + ')');
  $( ".g-recaptcha" ).css('-webkit-transform', 'scale(' + scale + ')');
  $( ".g-recaptcha" ).css('transform-origin', '0 0');
  $( ".g-recaptcha" ).css('-webkit-transform-origin', '0 0');
};

$( document ).ready(function() {

    $( window ).on('resize', function() {
        resizeReCaptcha();
    });

    resizeReCaptcha();

});

I'm updating things on the v1.2 branch. One of those things is an example of the invisible reCAPTCHA which may make your life easier as you no longer need to display the button. The challenge will only be shown when the user does not pass the automatic tests. This will also include v3 API support which doesn't show challenges at all, just returns a confidence score.

...and here we are nearly the end of 2018 and this is _still_ an issue; piss poor Google, piss poor.

+1 This is still a problem. Why hasn't this been patched yet?

Example hosted at https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php

The example is for v3 the invisible one, the ticket is about v2 where v3 didn't exist until now. So if v2 still relevant for the users, please reopen the ticket. This will not solve the initial problem of the styling. thx. @rowan-m

3 and half years have passed and still we dont have responsive re-captcha :(

Use below mentioned code

.g-recaptcha {transform: scale(0.85); transform-origin: left top;}

image

It seems like the responsiveness issues come from the fact that it's in an iframe and it can't really tell the size of it boundaries from in there. I'm surprised we can apply styles to it.

+1

Dear Google,

It's 2019. People have begun using their phones to access the internet. 🤯Also, V3 is not a new version, but rather a completely different approach to bot mitigation. Please fix V2.

Thank you,
Developers everywhere

++1 I really really dislike the V3 approach, it is an utterly insane time consuming frustration when it triggers. and I refuse to expose any of my clients or their clients to the possibility of it... Whenever I trigger V3 I tend to leave the page if I can... I suspect most people do...

If anyone stumbles upon this and still looks for a solution for V2 just something which I found worked for me. Ill update this with a fiddle when I get home to demonstrate the idea:

I had a similar issue for the recaptcha checkbox itself I ended up recreating the recaptcha box (the surrounding element). Basically you adjust the iframe to contain just the checkbox and the i am not a robot text i then recreated the whole area surrounding the recaptcha so that it can be restyled. Its a bit of a crude solution but it did solve this for me.

As for the recpatcha challenge popup you will notice that it does not fit into the device on mobile screens. What you could do (feels like a crude solution) set up an interval which will look for an element with a class 'g-recaptcha-bubble-arrow' once located add a class to its parent div which will let you style the element. Or you could directly apply your styles via js to the parent.

For the recaptcha popup, if you have this kind of structure:

<div style="[...]">
    <div style="[...]">
    </div>
    <div class="g-recaptcha-bubble-arrow" style="[...]">
    </div>
    <div class="g-recaptcha-bubble-arrow" style="[...]">
    </div>
    <div style="[...]">
        <iframe title="recaptcha challenge"
            src="https://www.google.com/recaptcha/api2/[...]"
            name="[...]" frameborder="0" scrolling="no"
            sandbox="[...]"
            style="[...]">
        </iframe>
    </div>
</div>

you can use

.g-recaptcha-bubble-arrow + div:not(.g-recaptcha-bubble-arrow) {
    overflow-y: scroll;
    height: 90vh !important;
}

it will add scrollbar in the popup

Its been some time since i looked at it but to give an example if what I meant by my comment i created this little "plugin" if you could call it that. I have to fix a few things for it but it may give someone an idea.

https://github.com/datorman/ResponsiveRecaptchaV2

Not a perfect solution but hopefully can help someone.

Really the issue is the style left:146px given to the div that surrounds the recaptcha - at least for me but I'm not sure if anyone else sees this as an issue. Unfortunately, I can't seem to adjust this manually at work without using query selector all and being super specific about it, but I'm willing to make a PR to fix this issue if needed.

@rowan-m

Thanks everyone!

I used some of the advice above but was having trouble with it being centred on mobile.

See the following for my full fix:

```
@media screen and (max-width: 414px) {
.g-recaptcha {
position: relative;
left: 50%;
-o-transform: scale(0.8) translateX(-50%);
-ms-transform: scale(0.8) translateX(-50%);
-moz-transform: scale(0.8) translateX(-50%);
-webkit-transform: scale(0.8) translateX(-50%);
transform: scale(0.8) translateX(-50%);
-o-transform-origin: left center;
-ms-transform-origin: left center;
-moz-transform-origin: left center;
-webkit-transform-origin: left center;
transform-origin: left center;
}
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Chaython picture Chaython  Â·  5Comments

edwolfe3 picture edwolfe3  Â·  10Comments

ryanbr picture ryanbr  Â·  14Comments

Antaris picture Antaris  Â·  11Comments

galford-tillster picture galford-tillster  Â·  5Comments