chapter one

1 Web dev math fundamentals

 

This chapter covers

  • Improving web dev precision with math
  • The benefits of learning web dev math
  • How math is used in CSS and JavaScript
  • The math basics for coding motion and animation, layouts, and user interactions

When you design or code a website, you might not think of yourself as doing math, but there’s likely at least a little mathematics behind most of what you do. Are you using relative units such as em or rem? There’s math behind those units. Are you applying an easing function such as ease-in-out to an animation? There’s math behind that function. Does your JavaScript code call the getBoundingClientRect() method on an element to determine its size and position? There’s math behind that method.

Certainly, it’s possible to design and develop websites without giving math more than a cursory thought. Whatever math lies underneath a unit such as em or an easing function such as ease-in-out might not matter to you as long as the job gets done. However, the whole point of this book is that if you take a bit of time to understand that math, you’ll find it makes a big difference in the precision and robustness of your web layouts and interfaces. The good news is that you don’t need a graduate degree to build better websites. You only need to understand a small set of concepts, and none of it is as complex as the CSS and JavaScript you already know.

1.1 Why bother learning about frontend math?

1.2 Why math matters in frontend development

1.2.1 The connection between mathematics and web design

1.2.2 Real-world examples of math in UI/UX

1.2.3 How developers use math in animations, layouts, and interactions

1.3 The role of mathematics in CSS and JavaScript

1.3.1 How CSS uses math

1.3.2 JavaScript’s built-in mathematical capabilities

1.3.3 Comparing CSS and JavaScript math approaches

1.4 The minimum math you need to know

1.4.1 Arithmetic and arithmetic expressions

1.4.2 Algebra

1.4.3 Ratios

1.4.4 Exponents and nth roots

1.4.5 Linear equations

1.4.6 Inequalities and comparison expressions

1.4.7 Geometry

Summary