Desmos uses curly braces with a specific condition-colon-formula pattern to graph piecewise functions. Once you learn the syntax, you can enter even complex multi-piece functions in a single expression line and get a clean, accurate graph in seconds.
The Basic Syntax
Every piecewise function in Desmos lives inside a pair of curly braces { }. Inside those braces, each piece follows the same structure: the condition comes first, then a colon, then the formula. If your function has more than one piece, you separate them with commas.
The general pattern looks like this:
f(x) = {condition1: formula1, condition2: formula2, condition3: formula3}
So a three-piece function like “f(x) equals negative 4 when x is less than or equal to negative 1, equals x squared plus 2 when x is between negative 1 and 3, and equals 4x minus 1 when x is greater than 3” would be typed as:
f(x) = {x <= -1: -4, -1 < x 3: 4x - 1}
A few details to note. You type “less than or equal to” as <= and “greater than or equal to” as >=. Desmos will automatically render these as the proper math symbols (≤ and ≥) once you finish typing. You can use strict inequalities (< and >) or non-strict ones depending on which endpoints your function includes.
Step-by-Step Entry
Open the Desmos graphing calculator and click on an empty expression line in the left panel. Type f(x) = followed by an opening curly brace. As soon as you type the brace, Desmos recognizes you’re building a piecewise expression.
Type your first condition, such as x <= 2, then type a colon. After the colon, type the formula for that interval, like 3x + 1. To add the next piece, type a comma. Desmos will give you space to enter another condition-colon-formula set. Repeat for as many pieces as your function has. When you’re done, close the curly brace or just press Enter, and Desmos will render the graph.
You don’t need to name the function f(x). You can type the piecewise expression by itself starting with y =, or name it g(x), h(x), or whatever you like. Naming it is useful if you want to reference the function later, for instance to evaluate f(3) or plot a point on the curve.
Open and Closed Circles at Endpoints
Desmos automatically draws open and closed circles at the boundaries of each piece based on the inequalities you use. A strict inequality (like x < 3) produces an open circle at that boundary, meaning the endpoint is excluded. A non-strict inequality (like x <= 3) produces a filled circle, meaning the endpoint is included.
This means you need to be careful about how you write adjacent conditions. If one piece covers x <= 3 and the next covers x > 3, the point at x = 3 belongs to the first piece and will show a closed dot there, with an open dot on the second piece. If you accidentally write both as x <= 3 and x >= 3, the function is defined twice at x = 3, and Desmos will graph both values at that point. Keep your boundary inequalities complementary so each x-value belongs to exactly one piece.
Simple Domain Restrictions
If you just want to graph a regular function over a limited domain rather than a true piecewise function, you can use the curly brace syntax with a single condition and no colon. For example, typing y = x^2 {0 < x < 5} graphs the parabola only between x = 0 and x = 5. This is handy when you want to show just one segment of a curve without writing a full piecewise definition.
You can also combine two conditions in one restriction using inequalities chained together. Typing {-1 < x <= 4} after a formula restricts the graph to that interval, with an open circle at negative 1 and a closed circle at 4.
Adding Sliders for Interactive Graphs
Desmos lets you replace any fixed number with a variable, then control that variable with a slider. This works inside piecewise functions too. If you type something like f(x) = {x <= a: x + 1, x > a: -x + 5}, Desmos will detect that a is undefined and offer to create a slider for it. Once you add the slider, dragging it moves the breakpoint between the two pieces in real time.
You can use sliders for the formulas themselves, not just the boundaries. Typing {x <= 0: m*x + b, x > 0: c*x^2} gives you sliders for m, b, and c, letting you reshape each piece independently. If you use the same variable name in multiple expressions on different lines, those expressions share the slider, so they all update together.
Plotting Points Along a Piecewise Curve
Once you’ve defined a named piecewise function like f(x), you can plot any point on it by typing a coordinate pair that references the function. For example, typing (2, f(2)) places a point on the graph wherever the function evaluates at x = 2. Combine this with a slider by typing (a, f(a)), and you get a point that slides along the entire piecewise curve as you drag the slider, jumping between pieces at each boundary.
This is especially useful for visualizing continuity and discontinuity. As you drag the slider through a breakpoint, you can see whether the point moves smoothly or jumps to a different value.
Tips for Clean Graphs
Color-coding helps when your graph has multiple piecewise functions. Click the colored circle to the left of any expression line to change its color, or to adjust the line style (solid, dashed, dotted).
If your piecewise function has many pieces and the expression line gets crowded, you can break it across multiple expression lines using domain restrictions instead. Graph y = 3x + 1 {x <= 0} on one line and y = -x + 4 {x > 0} on another. The visual result is the same, though the pieces won’t be linked as a single named function.
To add a label or annotation at a specific point, click on the point after plotting it and type a label in the box that appears. This is useful for marking the coordinates of breakpoints or endpoints on your piecewise graph, especially if you’re preparing the graph for a class or presentation.

