Sub topic 4
Drawing the grid: four lines, four intersections
This chapter covers the geometry of the thirds grid. You will learn how to compute its lines and intersections for any frame, and how to draw it in code and CSS. It assumes you know what an image frame is, including its width, height, and aspect ratio. It also assumes you can read short Python and CSS snippets.
What the grid is
The rule of thirds divides a frame into nine equal rectangles. Two vertical lines cut the width into three equal columns. Two horizontal lines cut the height into three equal rows. The result is a 3 by 3 table laid over the image.
The grid has two kinds of features:
- Four lines: two vertical and two horizontal.
- Four intersections: the points where a vertical line crosses a horizontal one. Photographers sometimes call these "power points" or "crash points". The names are informal. The points have no special physical meaning.
The frame's outer edges are not counted as grid lines. They are the border the grid sits inside.
The formulas
Let W be the frame width and H the frame height. Measure from the top-left corner, with x growing to the right and y growing downward. This is the convention used by image libraries, CSS, and most design tools.
| Feature | Position |
|---|---|
| Left vertical line | x = W / 3 |
| Right vertical line | x = 2W / 3 |
| Upper horizontal line | y = H / 3 |
| Lower horizontal line | y = 2H / 3 |
Each intersection pairs one x value with one y value, so there are 2 × 2 = 4 of them:
| Intersection | Coordinates | Common name |
|---|---|---|
| Upper left | (W / 3, H / 3) | top-left power point |
| Upper right | (2W / 3, H / 3) | top-right power point |
| Lower left | (W / 3, 2H / 3) | bottom-left power point |
| Lower right | (2W / 3, 2H / 3) | bottom-right power point |
Notice that the formulas depend only on the width and height. The same code works for a square, a 3:2 photo, a 16:9 video frame, or a tall phone screen. The cells take the aspect ratio of the frame. In a 16:9 frame, each cell is also 16:9. The cells are not squares unless the frame is square.
Computing the grid in Python
Here is a small function that returns the line positions and the four intersections.
def thirds_grid(width, height):
xs = [width / 3, 2 * width / 3]
ys = [height / 3, 2 * height / 3]
intersections = [(x, y) for x in xs for y in ys]
return xs, ys, intersections
xs, ys, points = thirds_grid(1920, 1080)
print(xs) # [640.0, 1280.0]
print(ys) # [360.0, 720.0]
print(points) # [(640.0, 360.0), (640.0, 720.0), (1280.0, 360.0), (1280.0, 720.0)]For a 1920 by 1080 frame, the vertical lines sit at x = 640 and x = 1280. The horizontal lines sit at y = 360 and y = 720. The list comprehension loops over xs first, then ys. That is why the points come out grouped by column: both points at x = 640 come before the points at x = 1280.
Pixel rounding
Most frames do not divide evenly by three. A 1000 by 667 frame gives lines at 333.33 and 666.67 horizontally. Pixels are whole units, so a drawing routine has to round. Rounding to the nearest pixel is normal, and the error is at most half a pixel. That is invisible in practice.
Two details are worth knowing:
- Compute with the exact value, then round once at the end. If you round
W / 3first and then double it, the second line can drift by one pixel. - A one-pixel line drawn at a fractional coordinate may look blurred in some tools because it straddles two pixel rows. Rounding to a whole pixel, or adding 0.5 in canvas-style APIs, gives a crisp line.
Seeing the structure
The diagram below shows the order in which you build the grid from a frame. Both pairs of lines come from the same split, applied once to each dimension.
Drawing the grid as an overlay
On the web, a nine-cell CSS grid gives you the overlay without changing the image. This example places the overlay over a photo.
.photo {
position: relative;
}
.thirds-overlay {
position: absolute;
inset: 0;
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, 1fr);
pointer-events: none;
}
.thirds-overlay > div {
border: 1px solid rgba(255, 255, 255, 0.6);
}The matching markup is a container holding the image and an overlay with nine child div elements:
<div class="photo">
<img src="landscape.jpg" alt="A lake at sunset">
<div class="thirds-overlay">
<div></div><div></div><div></div>
<div></div><div></div><div></div>
<div></div><div></div><div></div>
</div>
</div>How it works:
position: relativeon.photomakes it the reference box for the overlay.inset: 0stretches the overlay to cover the full box.repeat(3, 1fr)creates three equal columns and three equal rows.1frmeans one equal share of the free space.pointer-events: nonelets clicks and hovers pass through to the image underneath.- Each cell draws a thin semi-transparent white border. Where two cells meet, the borders sit side by side, so interior lines look about twice as thick as the outer edge. The outer edge also gets a border, which you may not want.
The CSS grid divides the box into exact thirds for any size, so the overlay follows the image if it resizes. You do not compute pixel positions yourself.
Common errors with the CSS overlay
- Overlay does not line up with the image. The
.photocontainer is larger than the image, for example because of extra padding or inline-image spacing. Make sure the container wraps the image tightly, or setimg { display: block; }. - Overlay blocks clicks. You left out
pointer-events: none. - Lines vanish on bright areas. A white line on a white sky disappears. Use a darker or two-tone line if your images vary, such as a light line with a thin dark shadow.
- Doubled interior lines. Adjacent borders stack. If you want single-width lines, give each cell only a right and bottom border and remove the outer ones with
:nth-childrules, or draw four lines with gradients instead.
Common mistakes when working with the grid
- Mixing up the axes. Thirds along the width produce vertical lines. Thirds along the height produce horizontal lines. Swapping
widthandheightin a function gives a grid that fits a rotated frame. - Forgetting that the origin is top-left. In math class, y grows upward. In images, it grows downward. The "upper" line is at
H / 3, a smaller y value, not a larger one. - Measuring from the wrong box. If an image is cropped or has a border, compute the grid from the area you are actually composing. A frame with a 40-pixel mat on each side has its grid inside the picture, not the outer canvas.
- Treating the grid as exact law. The lines are guides. A subject "on the line" can be a few percent off and still work. Aim for close, not for pixel-perfect.
- Recomputing after a crop. Cropping changes
WandH, so the lines move. A subject on a third line in the full image is usually not on one in the cropped image. Check again after every crop.
Checking your numbers
A quick way to test any grid code is to verify properties that must always hold:
def thirds_grid(width, height):
xs = [width / 3, 2 * width / 3]
ys = [height / 3, 2 * height / 3]
intersections = [(x, y) for x in xs for y in ys]
return xs, ys, intersections
for w, h in [(1920, 1080), (1000, 667), (1080, 1920)]:
xs, ys, pts = thirds_grid(w, h)
assert len(pts) == 4
assert abs((xs[1] - xs[0]) - (xs[0] - 0)) < 1e-9 # equal columns
assert abs((w - xs[1]) - xs[0]) < 1e-9 # last column equal
assert abs((ys[1] - ys[0]) - ys[0]) < 1e-9 # equal rows
print(w, h, [(round(x), round(y)) for x, y in pts])The assertions confirm that the three columns have equal width and the three rows have equal height. The printed rounded points show how the same formulas behave on a landscape, an uneven size, and a portrait frame.
Where this fits
Knowing where the lines and points fall is the mechanical part of the rule of thirds. The next chapters use these coordinates to decide where to put a subject, where to put a horizon, and how much space to leave in front of a moving or looking subject.
Exercise
A frame is 2400 pixels wide and 1600 pixels tall. Give the x positions of the vertical lines, the y positions of the horizontal lines, and the coordinates of the lower-right intersection, measured from the top-left corner.
Show answer
Vertical lines are at x = 2400 / 3 = 800 and x = 2 × 2400 / 3 = 1600. Horizontal lines are at y = 1600 / 3 ≈ 533.3 (about 533) and y = 2 × 1600 / 3 ≈ 1066.7 (about 1067). The lower-right intersection pairs the larger x with the larger y, so it is at (1600, about 1067).
Exercise
You place a subject on the left vertical third line of a 3000 by 2000 photo. You then crop the photo to a region 1800 pixels wide that starts at x = 600. Where is the subject's x position in the cropped frame, and is it still on a third line?
Show answer
The subject was at x = 3000 / 3 = 1000 in the original. After cropping from x = 600, its new position is 1000 − 600 = 400. The cropped frame's left third line is at 1800 / 3 = 600. The subject is at 400, which is 200 pixels left of that line, so it is no longer on a third line. You would need to adjust the crop, for example starting it at x = 400 so the subject lands at 600.
Exercise
In the CSS overlay, what happens to clicks on the photo if you remove pointer-events: none from .thirds-overlay, and why?
Show answer
The overlay covers the whole image and sits on top of it, so it receives the clicks and hovers instead of the image. Anything attached to the image, such as a link or a zoom handler, stops responding. pointer-events: none makes the overlay ignore the pointer, so events reach the image underneath.