I was accepted for the position of Member technical staff for the team Zoho Show at Zoho corporation in June of 2017. Zoho Show is the Zoho’s answer to Google Slides in a feature-rich package. My first task as a Web Developer in Zoho show was to code a feature that allows the shapes drawn inside Show to have Inner/Outer Borders. Up until then, Zoho show had the option to just choose between different types of the border like dotted, dashed etc and to change their width, but not the alignment of the border with respect to the shape.
In HTML, an SVG element, be it a path, rectangle or a circle can have SVG stroke with the following properties
These properties can be used to modify various properties of SVG element like colour, stroke width, type of ending to an open path and they type of stroke respectively. But there is no property by which we can specify if a stroke should be aligned to the centre, inside or to the outside of a closed path.
Illustration showing the default(Center) stroke with the representation of inner/outer stroke for the shape with the same dimensions.
Due to the absence of property for rendering the stroke of shape in specified orientation, to achieve the above-illustrated effect of Inner/Outer Stroke, we need to use other means for manipulating the desired effect for an SVG shape.
The easiest way to achieve the required inner/outer stroke effect in SVG would be using the clip-path.
Inner Stroke
Creation of inner stroke for an SVG path is easy and involves two simple steps.
An example can be found here. Using this method we can get a clear inner stroke for any SVG path.
Outer Stroke
Outer stroke using clip-path is a bit tricky because of the nature of the clipping in SVG.
clip-rule = “evenodd”.Using the above method the clip-path with clip the space inside the shape thereby hiding the inner portion of the stroke. Refer here for an example.
Even though using clip-path is one of the easiest and fastest ways to render a clean model of inner/outer stroke. It has its own disadvantages. Some of them are
Using SVG clip-path one can render a clean inner/outer stroke thereby circumventing the lack of a much-needed requirement of a stroke-align properly in HTML.