HTML Guide
The attribute font-weight
can be used on SVG text elements like text
but not on g
container elements, and none
is not a valid value.
The font-weight
attribute refers to the boldness or lightness of the glyphs used to render the text, relative to other fonts in the same font family.
This attribute can be used with the SVG elements text
, textPath
, tref
and tspan
, but on on g
elements.
Its allowed values are normal
, bold
, bolder
, lighter
, or a number. The value none
is not valid for this attribute.
Here’s an example:
<svg viewBox="0 0 200 30" xmlns="http://www.w3.org/2000/svg">
<text y="20" font-weight="normal">Normal text</text>
<text x="100" y="20" font-weight="bold">Bold text</text>
</svg>
Alternatively, SVG text elements can also be stilyzed using CSS, like so:
<svg viewBox="0 0 200 30" xmlns="http://www.w3.org/2000/svg">
<text y="20" style="font-weight:normal">Normal text</text>
<text x="100" y="20" style="font-weight:bold">Bold text</text>
</svg>
Learn more:
Related W3C validator issues
The CSS font-style property is used to set the style of the font, such as normal, italic, or oblique. The value bold is not a valid value for font-style. Instead, you should use the font-weight property to set the boldness of the font. The valid values for font-weight are normal, bold, bolder, and lighter.
Here’s an example of how to use the font-weight property to set the text to bold:
<p style="font-weight: bold;">This text is bold.</p>
Alternatively, you can use a CSS stylesheet to apply the font-weight property to multiple elements:
<style>
p { font-weight: bold; }
h1 { font-weight: bolder; }
</style>
<p>This text is bold.</p>
<h1>This heading is even bolder.</h1>