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

  • SEARCH
  • Home
  • 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 402991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:10:33+00:00 2026-05-12T17:10:33+00:00

Suppose I have the following html, and no CSS <div> here is some content

  • 0

Suppose I have the following html, and no CSS

<div> 
  here is some content in this div. it stretches it out
  <br />and down too!
</div>

Now I want to get the actual pixel width and height that the browser has rendered this div as.

Can that be done with JS?

Thank you.

  • 1 1 Answer
  • 3 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-05-12T17:10:33+00:00Added an answer on May 12, 2026 at 5:10 pm

    Try getting a reference to your div and reading the offsetWidth and offsetHeight properties:

    var myDiv = document.getElementById('myDiv');
    var width = myDiv.offsetWidth; // int
    var height = myDiv.offsetHeight;
    

    offsetWidth/Height cumulatively measures the element’s borders, horizontal padding, vertical scrollbar (if present, if rendered) and CSS width. It’s the pixel values of the entire space that the element uses in the document. I think it’s what you want.

    If that is not what you meant, and you’d rather only the element’s width and height (i.e. excluding padding, margin, etc) try getComputedStyle:

    var comStyle = window.getComputedStyle(myDiv, null);
    var width = parseInt(comStyle.getPropertyValue("width"), 10);
    var height = parseInt(comStyle.getPropertyValue("height"), 10);
    

    The values above will be the final, computed pixel values for the width and height css style properties (including values set by a <style> element or an external stylesheet).

    Like all helpful things, this won’t work in IE.


    You say you are using jQuery. Well it’s trivial now, and works cross-browser:

    var width = $('div').css('width');
    var height = $('div').css('height');
    

    With jQuery you don’t need the first part of this answer, it’s all taken care of for ya 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following html: This a test of <code>some code</code>. <div class='highlight'>
Suppose you have this following code in HTML - <div id=pattern> <span class=a>Content</span> </div>
Suppose I have following html page. <html> <head> <link type=text/css rel=Stylesheet href=css/some.css /> </head>
Suppose I have the following HTML: <div id=test> <span style=display:inline;>foo</span> <span style=display:none;>bar</span> <span style=display:inline;>baz</span>
Suppose I have the following html: <div style=width:200px;height:200px;overflow:scroll> ... </div> If the stuff in
Suppose I have the following html: var testString = ' <span id='id'> <div> <table>
Suppose I have the following HTML: <div class=container> <span class=remove>remove</span> </div> and jquery: $(.container).delegate(.remove,
Suppose I have the following HTML and js <div> <div class=testdiv id=test1>test</div> <div class=testdiv
Suppose I have the following HTML snippet: <input type=text id=myinput /> Now I want
Suppose I have the following HTML code: <div id=container style=width: 960px> <div id=help_panel style=width:

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.