Tips to make the background rectangle workaround more bearable
As mentioned at: https://graphicdesign.stackexchange.com/a/74920/21867 based on https://stackoverflow.com/questions/11293026/default-background-color-of-svg-root-element the only reliable SVG background color solution seems to be to add a colored rectangle to the background.
Unfortunately, Inkscape does not have an option to export the SVG with that rectangle automatically added, related discussion, so to make things a bit more convenient, you could use the following tips:
Just make the background rectangle larger than the image, don't worry about making it the exact same size.
SVG supports objects outside of the viewport, and only what is in the viewport will show in the end.
Making the background rectangle be exactly as large as the image can be hard when:
- the image size is not a multiple of the grid size is not a multiple of the grid size, so you have no appropriate snap
- you keep resizing the image during development to have more room for certain components
You could also just enter exact coordinates/widths manually in Inkscape, but I don't think there's any advantage in doing so.
If you have a fixed target size, one alternative is to first make the rectangle, manually enter dimensions, and then Ctrl + Shift + D > "Resize page to drawing" (Ctrl + Shift + R) as mentions at: https://youtu.be/cLIYCJ0DM6Q?t=145
put the background in a separate layer below the top layer and lock it. Otherwise you are going to keep dragging it around by mistake when you would want to move foreground items instead. This tip is mentioned at: https://www.youtube.com/watch?v=cLIYCJ0DM6Q&t=196s
This also has the advantage that if you ever want to "Resize page to drawing" (Ctrl + Shift + R ) based on contents without the (oversized) background rectangle, you can just make the background layer invisible before Ctrl + Shift + R, and make it visible again aferwards, as Inkscape does not consider invisible layers for Ctrl + Shift + R.
Document properties (Ctrl + Shift + D) > Border > "Border on top of drawing", otherwise your background rectangle is going to hide the borders of the viewport, and you lose the notion of where you are inside the drawing.
Set "Document properties" (Ctrl + Shift + D) > "Checkered Background" to be able to know where your background is, otherwise it is hard to know where the background starts and ends to ensure that the entire canvas is covered
Alternatively, you can also add a border to the background rectangle. But I'd rather keep the potential for noise on the output to a minimum.
-b on the command line for PNG export
E.g. to get a white background instead of the now default transparent:
inkscape -b FFFFFF -h 1024 input.svg -o output.png
Tested on Inkscape 1.0.1, Ubuntu 20.10.