You can’t bold just one word unfortunately unless you can wrap a tag around it and you can’t do that with the content property as tags are not allowed as content.
As usual you can ‘hack’ something into submission but has a very limited scope and depends on circumstance.
Your best bet is to change the html so that it allows you to do what you want.
The simple answer is NO you can’t bold a single word in that snippet.
Your choices are as follows:
Adjust the html so that it allows you to do what you want (add an empty tag at the start of the element and then you can target it with the content property for just one word).
Use js to find the word you want and then add suitable tags around the word to allow you to style it from the css.
Use the hack that I have shown in my codepen albeit that it has very limited use cases and will be hit and miss.
Use an image in the content property instead of text.
I can find the unicode for the regular but cant find for the Bold like for latin ‘C’ its U+1D04 and for bold C it is 1d402, I want similar for Devnagari
The bold ASCII is really a “cheat” in that it’s an abuse of the intended use
Unicode expressly recommends that these characters not be used in general text as a substitute for presentational markup; the letters are specifically designed to be semantically different from each other.
AFAIK Devanagari characters are not used in mathematical formulae. In other words, you will need one of the approaches PaulOB mentioned in post # 5
<off topic> @sachinkit, May I ask why the wish to create one bold work in a generated string is being sought? Is this a school project or a client’s order?
Interestingly, about two or three times a year, several members will ask very similar odd questions within a very few days. Within the past two days, at least 3 people have asked a question very similar to this one. It seems funny, so I am simply curious to know why.
You do not have to answer if you do not wish to. I am just very curious.
Yes that could be a problem as some browsers are now taking note of generated content and announcing them. They would likely get a mathematical equation read out rather than text.
<!DOCTYPE HTML><html lang="en"><head><meta charset="utf-8">
<title>Single Word Bold</title>
<style>
.test{
}
.test:before{
float:left;
content:"This is my\a0";
}
.test:after{
float:left;
font-weight:bold;
content:"Code:\a0";
}
</style>
</head><body>
<div class="test"> This is the normal text in the div.</div>
</body></html>
It would work if the div contains only one line of text.
Yes, if the OP could add something like an empty span or anything that can hold the generated content this floated bold word is going to work as wanted I think.
I have added an empty span to the JSFiddle:
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8">
<title>Make Single Word Bold</title>
<style>
div{
padding:1em;
}
.test{
display:block;
overflow:hidden;
}
.test:before{
float:left;
content:"This is my\a0";
}
.test:after{
float:left;
font-weight:bold;
content:"Code:\a0";
}
</style>
</head><body>
<div class="test"> This works when the div has only one line of text. Resize window to test.</div>
<div><span class="test"></span> This works also when the div has more than one line of text. Resize window to test.</div>
</body></html>
EDIT)
I didn’t notice that.
I then suggest making the span a block display. (Edited the code above.)