Create a rectangle and drag it to be a thin line, then follow the steps below.
For example, this is a 2pt rectangle with a gradient, and a regular 2pt line that’s solid yellow.
Click a shape or text box to select it, or select multiple objects.
In the Format sidebar, click the Style tab.
Choose one of the following:
-
A color or gradient designed to go with the theme: Click the color
well next to Fill, then choose a color or gradient. -
Any color: Click the disclosure arrow next to Fill, then click the Fill pop-up menu and choose Color Fill. Click the color wheel,
then choose a color from one of the color palettes. -
A two-color gradient fill: Click the disclosure arrow next to Fill, click the Fill pop-up menu and choose Gradient Fill, then
choose colors. The color well shows colors that match the theme; the
color wheel opens the Colors window, where you can choose any color.
Use the controls to change the angle and direction of the gradient. -
A custom gradient: Click the disclosure arrow next to Fill, click the Fill pop-up menu and choose Advanced Gradient Fill, then click the color stops below the slider to choose colors. Click the slider to add another color stop. You can drag the color stops and use the other controls to change the blend, angle, and direction of the gradient.
From: https://support.apple.com/guide/keynote/fill-objects-with-color-or-an-image-tan754f55080/mac

