
Making objects partially transparent
Objects in Inkscape can be made partially transparent by manipulating their opacity level, so that the background and the objects below them show through.
The default Canvas background color in Inkscape is fully transparent (zero opacity), and therefore invisible. Although this isn't indicated by a checkerboard pattern like in some other graphics applications, when we export our drawing to the PNG format, the background (space around objects) will be transparent.
Tip
Exporting to PNG and transparency
Always use the Export Bitmap option when converting your drawing to the PNG format, and not Save as... | Cairo PNG. The latter may give unexpected results, including an opaque (white) background instead of a transparent one.
In this recipe we will create a number of objects with different levels of transparency applied to them. The final result should resemble the following screenshot:

Getting ready
Start Inkscape and open the Fill and Stroke dialogue. Here we will find various options for manipulating the opacity of our objects. Changes in the opacity can be observed on a flat color background but are even more obvious if there is a pattern in the background.
Inkscape comes with several textured pattern fills; the most appropriate in this case are probably the Camouflage, Cloth (bitmap), and Old paint (bitmap) options. Create a large rectangle the size of your page and click on the Fill to Pattern button to set its fill to one of the three previously mentioned patterns.
How to do it...
Carry out the following steps:
- Select the Rectangle tool (F4).
- Click and drag to create a small rectangle.
- Change the stroke width to 32 using the Stroke width box in the bottom left of the Inkscape window (click with the right mouse button).
- Change the rectangle Fill color to yellow and Stroke color to purple using color chips from the color palette.
- Switch to the Selector tool (F1 or Space).
- Duplicate the rectangle five times so you have six in total. You can do this using the Duplicate button
(Ctrl + D) or with stamping (click and hold the rectangle, don't release the mouse, and hit Space to drop a copy of the rectangle in that place while still not releasing the mouse).
- Select the first rectangle and make sure that in the Fill and Stroke dialogue window the Opacity, % slider is set to 100, and the A (Alpha) opacity box of both fill and stroke is set to 255.
- Select the second rectangle and set the Opacity, % slider to 60 while keeping the A opacity box of both fill and stroke at 255.
- Select the third rectangle and set the fill A opacity box to 150 while keeping the Opacity, % slider at 100 and the stroke A opacity box at 255.
- Select the fourth rectangle and set the stroke A opacity box to 150 while keeping the Opacity, % slider at 100 and the fill A opacity box at 255.
- Select the fifth rectangle and set the Opacity, % slider to 100 and both the fill and stroke A opacity box to 150.
- Select the sixth rectangle and set the Opacity, % slider to 80 and both the fill and stroke A opacity box to 150.
- Optionally, add the text labels next to each of the rectangles to mark which transparency changes were made.
How it works...
Here's the table of opacity styles applied in this recipe:

As we can see from the earlier screenshot various effects can be achieved depending on where you apply the transparency. Making the whole object partially transparent or only setting the fill gives an expected result where you can see the background show through the whole object or only the fill area delimited by the fully opaque stroke.
In the second row, rectangles have their stroke only partially transparent; you'll have figured out by now that the stroke isn't actually positioned completely inside or outside the object, but it's actually centered on the object's edge, so that half of the stroke covers the fill and the other half is on the outside of the object.
When stroke is partially transparent and of a different color than fill, we can see that the colors mix in the area where stroke covers the fill producing a different hue. This effect gives the impression that we used more than one object to achieve this, and will come in handy in order to simplify your SVG document structure. It can also be used easily to add edge enhancement effects to your objects, such as buttons or information boxes.
There's more...
Just as you can make whole fill and stroke equally transparent across the entire surface of the object, you can also gradually apply varying transparency levels using gradients.
Note
If you find yourself dealing with the haunting presence of a stubbornly invisible shape, revealing itelf only through its bounding box, don't panic: the poor object is probably having a bad case of "zero opacity" blues. To "cure" it and make it appear again, reset its Opacity value back to 100 (fully opaque).
Advanced effects, called SVG filters, can also produce partial transparency on objects and often much more complex effects than we have seen in this recipe. SVG filters deserve special attention so they are covered in detail in Chapter 5 of this book.
The Cloth (bitmap) pattern used in this recipe was made by a Wikimedia user, SoylentGreen. The original bitmap can be accessed at:
See also
For more information, refer to the recipe on Masking in Chapter 1, and also Creating linear gradients, Recreating HAL 9000 using radial gradients, and Picking and assigning colors with the Dropper tool in this chapter.