Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:12:39+00:00 2026-06-14T20:12:39+00:00

I’ve created a simple canvas element <canvas style=width:100%;height:100%; id=canvas></canvas> when I try to get

  • 0

I’ve created a simple canvas element

<canvas style="width:100%;height:100%;" id="canvas"></canvas>

when I try to get the height, however in javascript:

var canvas = document.getElementById(config.elementId);
console.log(canvas.height); //150
console.log(canvas.width); //300

console.log(canvas.style.height); //100%
console.log(canvas.style.width); //100%

If I inspect the element in chrome’s debugger, and actually mouse over the element, chrome is reporting the element size as

1627x925px

How on earth do I get to the 1627x925px measurements in js?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:12:41+00:00Added an answer on June 14, 2026 at 8:12 pm

    As @Alex says, you can use the getComputedStyle function to get the current size of the canvas.

    But… to make the canvas full screen width and height always, meaning even when the browser is resized, you need to run your draw loop within a function that resizes the canvas to the window.innerHeight and window.innerWidth.

    Once you do that, you can use the normal canvas.height and canvas.width functions to get properly the canvas size:

    (function() {
        var canvas = document.getElementById('canvas'),
        context = canvas.getContext('2d');
    
        // resize the canvas to fill browser window dynamically
        window.addEventListener('resize', resizeCanvas, false);
    
        function resizeCanvas() {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
    
            /* Your drawings need to be inside this function
             * to avoid canvas to be cleared. */
            drawStuff(); 
        }
        resizeCanvas();
    
        function drawStuff() {
            console.log(canvas.height); //925
            console.log(canvas.width); //1627
            // do your drawing stuff here
        }
    })();
    

    Plus: Use this CSS hacks to make the canvas full size without problems:

    /* remove the top and left whitespace */
    * { margin:0; padding:0; } 
    
    /* just to be sure these are full screen*/
    html, body { width:100%; height:100%; }
    
    /* To remove the scrollbar */
    canvas { display:block; } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a small JavaScript validation script that validates inputs based on Regex. I
I am currently running into a problem where an element is coming back from
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.