How can I bold the first word of sentence using CSS selectors and is this a good/bad way to do this with respects to browser comparability?
code:
<h2>this is a sentence</h2>
thx
To bold text simply for decoration, use the CSS font-weight property instead of the HTML strong element. Let's say you want to bold a word in a paragraph — you'd wrap the word in <span> tags and use a CSS class selector to apply the font-weight property to the specific span element only.
Solutions with CSS and HTML If you want to change the color of the first word of a text, you can use the CSS :before pseudo-element, which is used to add any element. Its value is defined with the content property. If it is not used, the content will not be generated and inserted.
To make text bold in HTML, use the <b>… </b> tag or <strong>… </strong> tag. Both the tags have the same functioning, but <strong> tag adds semantic strong importance to the text.
There is no ::first-word
pseudo-element in CSS; you'll have to wrap the first word in an extra element and then select that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With