Checkout my coding YouTube channel!

Suggestions

TLDR; Not Your Typical Privacy Agreement

  • This chatbot does not store previous messages. It uses ephemeral message storage meaning your conversation will be lost when you close the browser window.
  • Please cross-reference all AI responses because they may be inaccurate but highly unlikely.
  • This chatbot is free of use and does not require a subscription.

Powered by Cohere

Samsung Galaxy S10e

Specifications

  • Dimensions: 142.2 x 69.9 x 7.9 mm (5.60 x 2.75 x 0.31 in)
  • Weight: 150 g (5.29 oz)
  • Display: Dynamic AMOLED, HDR10+
  • Resolution: 1080 x 2280 pixels, 19:9 ratio (~438 ppi density)
  • OS: Android 9.0 (Pie), upgradable to Android 12, One UI 4.1
  • CPU: Octa-core (2x2.73 GHz Mongoose M4 & 2x2.31 GHz Cortex-A75 & 4x1.95 GHz Cortex-A55) - EMEA/LATAM
  • Main Camera: 12 MP, f/1.5-2.4, 26mm (wide)
  • Selfie Camera: 10 MP, f/1.9, 26mm (wide), 1/3", 1.22ยตm, dual pixel PDAF
  • Battery: Li-Ion 3100 mAh, non-removable
All Notes

Browser Mathematics

Saturday, September 13, 2025
Author:
Share to Reddit
Share to Facebook
Share to X
Share to LinkedIn
Share to WhatsApp
Share by email
Describing the associated blog post


The web browser๐Ÿ˜ฒ. One of the greatest inventions on our planet. You are probably reading this article using one. There's an 80% chance that the browser you are using is Google Chrome, Microsoft Edge, or Safari. There is also a 95% chance that you are not reading this article from Internet Explorer (RIP).

rest in peace

A web browser is an application software that enables users to navigate and search the internet for information. A key aspect of internet searching is user experience and accessibility. I want to focus on user experience in this article, specifically how elements are rendered on a web page and the numbers associated with that.

Box Sizing

Box sizing is a CSS property that specifies the behavior of the 'width' and 'height' properties. It is most commonly used with a value of either border-box or content-box. You might have seen CSS code that looks like this:

body {
    box-sizing: border-box;
}

Depending on your project and approach to writing CSS styles, the code above simply tells the browser to include the border of every HTML element when calculating the width and height. A value of content-box does the opposite, it tells the browser to calculate the dimension of elements by excluding the border of the element.

This is something that will most likely not affect the visual aspect of a web page, but if you inspected using developer tools, you would understand exactly how these values are calculated. Have a look at the picture below. Content box excludes the border part from the height and width whereas border box includes it.

Browser dimensions

CSS Units

In Cascading Style Sheets, there are multiple unit types to choose from when styling elements.

.box{
    width: 100px;
    height: 80px;
}

The px part of the code snippet above can easily be replaced with the following:

Unit Meaning Example
px Pixel units 200px
% Represents a percentage of the parent element 50%
vh Viewport height, which represents a percentage of the browser height. 75vh
vw Viewport width, which represents a percentage of the browser width. 50vw
dvh Dynamic viewport height, which adjusts the height on mobile browsers. 100dvh
dvw Dynamic viewport width, which adjusts the width on mobile browsers. 100dvw
svh Small viewport height. 100svh
svw Small viewport width. 100svw

There are several other unit types, but these are the most common. CSS also allows us to do math using a special calc function

.box{
    width: calc(10px * 50px);
}

This evaluates a mathematical expression, and the following operators can be used: +, -, *, and /.

  • Multiplication: width: calc(10px * 50px);
  • Division: width: calc(10px / 50px);
  • Addition: width: calc(10px + 50px);
  • Subtraction: width: calc(10px - 50px);

JavaScript Calculations

There are default values that cannot be changed by us. These are typically defined by the size of the device. For example, we have the innerWidth property on the window object which is read-only and returns the interior width of the window in pixels (that is, the width of the window's layout viewport). For example:

console.log(window.innerWidth)
console.log(window.innerHeight) // including the height of the horizontal scroll bar, if present.
console.log(window.outerWidth) // returns the width of the outside of the browser window.
console.log(window.outerHeight) // returns the height in pixels of the whole browser window, including any sidebar, window chrome, and window-resizing borders/handles.

There is also the function called getBoundingClientRect that returns a position relative to the viewport.

const element = document.getElementById("content")

console.log(element.getBoundingClientRect())
console.log(element.clientWidth) // This is zero for inline elements and elements with no CSS; otherwise, it's the inner width of an element in pixels.
console.log(element.offsetWidth) // returns the layout width of an element as an integer.
console.log(element.scrollWidth) // measurement of the width of an element's content, including content not visible on the screen due to overflow.
console.log(element.clientHeight) // This is zero for elements with no CSS or inline layout boxes; otherwise, it's the inner height of an element in pixels.
console.log(element.offsetHeight) // returns the height of an element, including vertical padding and borders, as an integer.
console.log(element.scrollHeight) // A measurement of the height of an element's content, including content not visible on the screen due to overflow.
console.log(element.style.width) // The width of the DOM element which is zero for inline elements and elements with no CSS
console.log(element.style.height) // The height of the DOM element which is zero for elements with no CSS

There is also the ResizeObserverSize constructor which is an interface of the Resize Observer API used by the ResizeObserverEntry interface to access the box sizing properties of the element being observed.

const size = new ResizeObserverSize()

console.log(size.blockSize) // returns the length of the observed element's border box in the block dimension.
console.log(size.inlineSize) // returns the length of the observed element's border box in the inline dimension.

Reaching Infinity (The End)

As you can see, numbers are an integral part of web development. Everything within the browser window has some kind of numbers associated with it. I, for one, really enjoy defining breakpoints, manipulating DOM elements, and reading their properties with the added advantage of instant visual feedback. The best part is that you don't need to have majored in the subject of Mathematics to understand how numbers work in the browser.

Feel free to share your comments to this article or get in touch with me. Happy coding and calculating๐Ÿ˜‰

More Articles

Tawanda Andrew Msengezi

Tawanda Andrew Msengezi is a Software Engineer and Technical Writer who writes all the articles on this blog. He has a Bachelor of Science in Computer Information Systems from Near East University. He is an expert in all things web development with a specific focus on frontend development. This blog contains articles about HTML, CSS, JavaScript and various other tech related content.

Comments

No comments for this post yet. Be the first to write a comment.

User Notice

Dear Visitor,

This website stores your color theme preference, you can toggle your theme preference using the lightbulb icon in the top right of the webpage.

Clicking on the robot icon that says 'Chat' in the bottom-left corner will open a chat with an AI assistant. Click the button below to close this message.